0

シンプルなAndroidアプリを開発しようとしています。検索条件を入力するための 2 つのテキスト ボックスがあります。ページを送信するための送信ボタン。次のページ (新しいインテント) で、検索結果を表示します。

今、リストビューで結果を検索したいと思います。ビューの xml コードは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">

 <ImageView
    android:id="@+id/image"
    android:layout_width="50px"
    android:layout_height="50px"
    android:layout_marginLeft="5px"
    android:layout_marginRight="20px"
    android:layout_marginTop="5px">
</ImageView>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" 
android:orientation="vertical">

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="15px" >
</TextView>
<TextView
    android:id="@+id/addr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="15px" >
</TextView>

XXXArrayAdapter クラスの getView メソッドでは、以下のように背景色を設定しています。

  private int[] colors = new int[] { 0x30FF0000, 0x300000FF };
 int colorPos = position % colors.length;
 rowView.setBackgroundColor(colors[colorPos]);

ただし、行全体に背景色が表示されません。以下のスクリーンショットをご覧ください。赤いボックスは無視してください。意図的に検索結果を非表示にしています。

4

1 に答える 1

1

レイアウトのルート LinearLayout 幅は、コンテンツをラップするように設定されています。画面全体を埋めるように match_parent に設定します

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
于 2012-10-21T17:38:15.637 に答える