【问题标题】:CustomListView background issueCustomListView 后台问题
【发布时间】:2012-10-16 21:08:24
【问题描述】:

我用图像自定义Listview。我的items.xml是这样的:

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

这是有效的,但当我触摸它并将其移动到我的自定义列表视图时,它就坏了。我觉得这个背景main.xml可能有问题:

我的main.xml是这样的:

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

我已经厌倦了更改其他属性,并且它不起作用。

【问题讨论】:

    标签: android xml listview layout background


    【解决方案1】:

    而不是放

    android:background="@drawable/gradient_body"
    

    在你的 main.xml 的列表视图中将它添加到你的 items.xml 中的 relativeLayout 中,就像这样

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

    【讨论】:

    • 感谢@Irfan.. 工作方式,但没有产生“点击”效果(默认,点击橙色效果)
    • 只需在您的列表视图中使用 android:drawSelectorOnTop="true" 即可获得您想要的效果
    • 是的.. 工作正常.. 谢谢@Irfan.. 但是如果想要的效果显示,文本是可见的.. 任何技巧?
    • 好吧,我没明白你的意思。您是否希望列表项的文本在您单击它的那一刻消失??
    • 事实上恰恰相反。如果我使用您的代码,文本将消失。如何保持文字不消失?
    猜你喜欢
    • 2015-03-27
    • 1970-01-01
    • 2020-04-10
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    相关资源
    最近更新 更多