0

これまでのところ、リストビューの背景を変更したいこれを試しました

<ListView
android:id="@+id/myList"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@color/white"/>

しかし、ここでは背景が機能していないようです。実際には、バックグラウンドのデフォルトの背景を示しています。

4

8 に答える 8

0

android:layout_height="fill_parent" 最初に、背景が正しく設定されているかどうかを確認してください

listview.setBackgroundResource(android.R.color.darker_gray);

独自の色をご希望の場合

listview.setBackgroundResource(R.color.Yellow);

および ur /res/strings.xml ファイル内

<color name="Yellow">#FF0</color> その他の色 http://en.wikipedia.org/wiki/Web_colors

于 2013-05-28T07:40:58.570 に答える
0

最初にセレクターを定義する必要があります。このように、list_bg.xml

        <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false" android:drawable="@color/BackgroundColor" />
    <item android:drawable="@color/white" />
</selector>

次に、これを背景として設定します。

 <ListView
android:id="@+id/myList"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="@drawable/list_bg"/>
于 2013-05-28T06:34:06.863 に答える
0

このリストのカスタム ListAdapter がある場合は、そのクラスの getView() メソッド内で簡単にレイアウトを変更できます。

お持ちでない場合は、カスタム テーマ内でこれら 2 つのパラメータを変更する必要があります

<item name="listChoiceBackgroundIndicator">@android:drawable/list_selector_background</item>

  <item name="activatedBackgroundIndicator">@android:drawable/activated_background</item>

リスト行の代替背景色など、別の要件があり、うまく機能したため、カスタムリストアダプター内でそれを行いました。2番目のオプションを試したことはありませんが、うまくいくはずです...カスタムテーマの他の選択肢については、このリンクを参照してください。

編集 string.xml 内にスタイルとテーマの宣言を記述しません。そのファイルは文字列宣言専用です。valuesフォルダー内にファイルthemes.xmlを作成します。次のチュートリアルを参照してください

  1. 簡単なチュートリアル
  2. 良いチュートリアル
  3. 最高のチュートリアル

上記の例のいずれかを参照してください。テーマが作成されたら、そのテーマを android-manifest ファイル内のアクティビティ/アプリケーションに適用する必要があります。また、既存のテーマを拡張する必要があります。

于 2013-05-28T06:39:08.913 に答える
0

Android 2.2 にはバグがあります。ベスト プラクティスは、画像を後ろにパントし、背景を null に設定することであることがわかりました。

<RelativerLayout 
android:layout_height="wrap_content"
android:layout_width="wrap_content">

   <ImageView
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"
   android:src="@drawable/list_bg"/>

   <ListView
   android:id="@+id/myList"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent"
   android:background="@null"/>

</RelativerLayout>
于 2013-05-28T07:58:38.963 に答える
0

各リスト項目レイアウトの色を変更してみてください。

アダプターをセットアップするときに、リスト項目の xml を見つけます。

public class YourListAdapter extends BaseAdapter {

   /....Code for Adapter ...../

         public View getView(int position, View view, ViewGroup parent) {
            if (view == null) {

            view = mInflator.inflate(R.layout.yourxml_listitem, null);

  /...rest of code for adapter .../

次に、リスト項目の xml レイアウトを編集し、各リスト項目に背景色を追加します。別の色を設定している、または色を透明に設定していると思われます。

于 2013-05-28T06:29:22.027 に答える
0
<ListView
android:id="@+id/myList"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:cacheColorHint="#00000000"/>

カスタムリストビューを使用している場合は、listitem latout で背景色を定義します。

listitem.xml // 言う

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/artists_list_backgroundcolor"
    android:baselineAligned="false"
    android:orientation="vertical" >
  // Your Listitem widgets

</LinearLayout>

このようにしてみてください..

于 2013-05-28T06:50:45.567 に答える
0

以下の行のように試してみませんか。

<LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="7dip"
                android:background="@drawable/list_white_bg" >

                <ListView
                    android:id="@+id/listView"
                    android:layout_width="wrap_content"
                    android:layout_height="170dip"
                    android:divider="#e0e0e0"                    
                     android:drawSelectorOnTop="false"
                    android:dividerHeight="1dip"
                    android:fadingEdge="none" >
                </ListView>
            </LinearLayout>
于 2013-05-28T06:56:24.627 に答える