0

リストに項目を追加するための黒いプラスの形をしたボタンを備えたシンプルな To Do リスト アプリがあります。Android 2.2 では、黒のプラスは次のようになります。

ここに画像の説明を入力

ただし、Android 4.1 では、黒のプラスは次のようになります。

ここに画像の説明を入力

plus は 2.2 と同じように見えるはずです。適切なフラグメントの xml は次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/widget78"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:focusable="true" android:focusableInTouchMode="true">
<ListView
    android:id="@+id/taskslist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="10" />
<LinearLayout
    android:id="@+id/widget83"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="12dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp">
<EditText
    android:id="@+id/taskname"
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"
    android:background="@drawable/edittextbackground"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="2dp"
    android:hint=" Add Something :)"
    android:textSize="18sp"
    android:windowSoftInputMode="adjustNothing"
    android:cursorVisible="true"
    android:textColor="#000000"
    android:textCursorDrawable="@null"
    android:layout_weight="9999999"/>
<!--    android:imeOptions="actionGo"
    android:inputType="textImeMultiLine" 
    --> 
<FrameLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">
<Button
    android:id="@+id/addtask"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/small_black_plus"
    android:layout_marginBottom="0dp"
    android:layout_gravity="center"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="0dp"
    android:text="" />
</FrameLayout>
</LinearLayout>
</LinearLayout>

2 つのバージョンでレイアウトが異なるのはなぜですか? それらを同じように見せるにはどうすればよいですか?

4

3 に答える 3

1

これは、リソース ファイルの管理方法と関係があるのではないかと考えています。テストしたデバイスの解像度は異なりますか? 表示される歪みは、OS が xhdpi 画面の drawable-mdpi または drawable-hdpi フォルダーに配置したリソースを自動的にスケーリングすることによって発生する可能性があります。

リソース ファイルの管理方法については、次の参考資料を参照してください。お役に立てば幸いです。

http://developer.android.com/guide/practices/screens_support.html

編集:

さらに、この質問を見てください。

違い: android:background と android:src?

他の人が触れたように、Button を ImageView に変更してみてください。ボタンの場合と同じ方法で onClickListener を設定することにより、Android の任意のビューをボタンとして使用できます。これを行う場合は、 のandroid:src代わりに属性を使用して画像ドローアブル リソースを設定してみてくださいandroid:background。Android のバージョンが異なるとビューのサイズが異なるかどうかわからないため、これが問題の原因であるとは思いませんが、おそらくこれら 2 つのアイデアの間で機能するものを見つけることができます。

于 2012-09-19T20:33:29.503 に答える
0

これは、4.1の新しいTabHostで「スクロール可能な」タブが使用できるためです。水平方向にスクロールする方法をご覧ください。

これをAndroidの両方のバージョンで正しく表示するために、さまざまなAPIレベルのリソース修飾子(フォルダー名内)を使用してViewStubを作成し、さまざまなタブに同じIDを使用しますが、フォントサイズを明示的に設定します。合わない(またはテキストを変更する、それはあなた次第です)

于 2012-09-19T20:22:31.130 に答える
0

または、ボタンの代わりにImageViewを使用することもできますが、どちらの場合も同じように機能します。

于 2012-09-19T20:23:19.203 に答える