Ofir A.
Ofir A.

Reputation: 3162

List view item layout in Android

I'm trying to set the background of the right arrow, that when I press it, only the background around the arrow will shown(till the separator).

I tried to do it with Image Button but when I do it like this, the list item can't be clickable.

this is my XML item list layout:

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="5dip"
    android:paddingLeft="2dip"
    android:paddingRight="2dip"
    android:paddingTop="5dip" >

    <ImageView
        android:id="@+id/itemlist_checkedd"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_checkitem" />


    <ImageView
        android:id="@+id/skinpreview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/itemlist_checkedd"
        android:scaleType="fitXY" />

   <ImageButton
        android:id="@+id/skinEdit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:adjustViewBounds="true"
        android:paddingLeft="10dip"
        android:background="@null"
        android:src="@drawable/ic_go_edit" />

    <ImageView 
        android:id="@+id/separator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="@id/skinEdit"
        android:layout_marginRight="5dip"
        android:src="@drawable/separator"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="15dip"
        android:layout_toRightOf="@id/skinpreview"
        android:layout_toLeftOf="@id/separator"
        android:textAppearance="?android:attr/textAppearanceLarge" />

This is how it looks:

enter image description here

Any suggestions??? Thanks.

Upvotes: 0

Views: 558

Answers (2)

Hesham Saeed
Hesham Saeed

Reputation: 5378

Create selector xml file in res/drawable

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

You will need to create another picture of the arrow with the highlighted background you need.

of course then assign your ImageView src to the xml file (arrow_selector.xml) for example

Upvotes: 1

Ishu
Ishu

Reputation: 5457

Just set the background color or an image to the parent view in this xml

Upvotes: 1

Related Questions