2012-04-01 143 views
0

我试图设置右箭头的背景,当我按下它时,只会显示箭头周围的背景(直到分隔符)。在Android中列表查看项目布局

我试图用图像按钮来做,但是当我这样做时,列表项不能点击。

这是我的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

任何建议??? 谢谢。

回答

1

创建资源选择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),例如

+0

感谢您的回答。另一个问题,我怎样才能伸展“箭头按下”的图像,这将适合整个右侧区域,直到分隔图像? – 2012-04-02 08:37:11

+0

只需在photoshop中为箭头按钮(大/小/蓝/拉伸)创建任何图像,如果您的意思是别的,您可以在代码中声明图像ImageView arrow =(ImageView)findViewById(R.id.arrow) ;然后使用箭头上的函数来播放该图像的xml属性,然后在onClick()函数中执行该操作。 – 2012-04-02 08:59:11

1

只需设置背景颜色或图像父视图在该XML