列出Android中的视图项布局

时间:2012-04-01 15:52:41

标签: android listview android-layout clickable

我正在尝试设置右箭头的背景,当我按下它时,只显示箭头周围的背景(直到分隔符)。

我尝试使用Image Button执行此操作但是当我这样做时,列表项无法单击。

这是我的XML项目列表布局:

    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" />

它的外观如下:

enter image description here

任何建议??? 感谢。

2 个答案:

答案 0 :(得分:1)

只需将背景颜色或图像设置为此xml中的父视图

即可

答案 1 :(得分:1)

在res / drawable

中创建选择器xml文件
<?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>

您需要使用所需的突出显示背景创建另一张箭头图片。

当然然后将您的ImageView src分配给xml文件(arrow_selector.xml),例如