Arief Rivai Arief Rivai - 2 months ago 17
Android Question

CustomListView background issue

I make a custom

Listview
with image. My
items.xml
is like this:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:soundEffectsEnabled="true"
>

<ImageView
android:layout_width="50dip"
android:layout_height="50dip"
android:id="@+id/imgViewLogo"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:scaleType="center">
</ImageView>

<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/txtViewTitle"
android:layout_toRightOf="@+id/imgViewLogo"
android:layout_marginLeft="2dip"
android:textColor="#000000">
</TextView>

<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/txtViewDescription"
android:layout_toRightOf="@+id/imgViewLogo"
android:layout_below="@+id/txtViewTitle"
android:layout_marginLeft="2dip"

android:textColor="#000000">
</TextView>

</RelativeLayout>


enter image description here

That's working, when but I touch it and move it my custom list view, it's broken. I think there may be problems with this background
main.xml
:

enter image description here

My
main.xml
is like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gradient_body"
android:focusable="true"
>
<ListView
android:id="@+id/listView1"
android:background="@drawable/gradient_body"
android:focusable="true"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:divider="#c0bbbb"
android:dividerHeight="1dp"
></ListView>
</LinearLayout>


I'm tired to change other attribute, and it isn't working.

Answer Source

Instead of putting

android:background="@drawable/gradient_body"

in the listview in your main.xml add it in relativeLayout in you items.xml just like this

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip"
android:background="@drawable/gradient_body"
android:soundEffectsEnabled="true" >