Listview background not appearing in Android
I have an item in my drawable folders called bg.png, however, it will not display as a background in my list view. All I get is the default black. What am I doing wrong? Does it need to be a specific size, or is the problem in my code? See below for main.xml:
<LinearLayout android:id="@+id/LinearLayout01"
xmlns:android="h开发者_开发问答ttp://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/bg">
<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:cacheColorHint="#00000000">
</ListView>
</LinearLayout>
Ok, use following code, it will work.
<LinearLayout android:id="@+id/LinearLayout01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg">
</ListView>
</LinearLayout>
The problem here may be that you need to set the background color of the listview items to this color too, because when the items are displayed the color shown is the backcolor of the listview items not the listview itself.
精彩评论