【问题标题】:List view item layout in AndroidAndroid中的列表视图项目布局
【发布时间】:2012-04-02 05:42:11
【问题描述】:

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

我尝试使用图像按钮来执行此操作,但是当我这样做时,列表项无法单击。

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

看起来是这样的:

有什么建议吗??? 谢谢。

【问题讨论】:

    标签: android listview android-layout clickable


    【解决方案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),例如

    【讨论】:

    • 感谢您的回答。另一个问题,我怎样才能只拉伸“按下箭头”的图像,这将适合整个右侧区域,直到分隔符图像?
    • 只需在photoshop中为arrow_pressed(更大/更小/蓝色/拉伸)创建您需要的任何图像,如果您的意思是别的,您可以在代码中声明图像,ImageView箭头=(ImageView)findViewById (R.id.箭头);然后使用箭头上的函数来使用该图像的 xml 属性并在 onClick() 函数中执行此操作。
    【解决方案2】:

    只需在这个xml中给父视图设置背景颜色或图片

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      • 1970-01-01
      • 2020-04-14
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 2013-01-29
      相关资源
      最近更新 更多