android - Android Listview中重叠文本和图像的图层顺序

标签 android listview imageview layer

[已更新,因为我显然还不能回答我自己的问题:这就像重新排序 View 一样简单。我将 TextView 放在末尾,指示 layout_alignParentLeft="true",它就成功了。]

我有一个典型的 ListView 项目描述,每行有文本和图像 (3)。

我注意到该行右侧的图像 (id="@+id/browse_item_row_icon") 绘制在文本之上(上方)。

虽然不是我想要的,但我认为它确实可以工作,如果我可以将该图像放在后面文本而不是在文本之上。这将允许我在必要时显示更多文本,并且遮盖部分图像不会影响可用性。

有没有办法指示 View 的上方/下方顺序?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    >

    <TextView      
        android:id="@+id/browse_item_row_text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="24dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="48dip"
      >
    </TextView>

    <ImageButton 
        android:id="@+id/browse_item_add_button" 
        android:background="@drawable/ic_add_button" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true">
    </ImageButton>

    <ImageView
        android:id="@+id/browse_item_to_submenu" 
        android:src="@drawable/expander_ic_minimized"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toLeftOf="@id/browse_item_add_button" >
    </ImageView>

    <ImageView 
        android:id="@+id/browse_item_row_icon" 
        android:src="@drawable/ic_default_image"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toLeftOf="@id/browse_item_to_submenu" >
    </ImageView>

</RelativeLayout>

最佳答案

好吧,在你的情况下,如果你想在 TextView 后面使用图像,你可以为此使用 FrameLayout,试试这个。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <FrameLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <RelativeLayout android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <ImageButton android:id="@+id/browse_item_add_button"
                android:background="@drawable/icon" android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true">
            </ImageButton>

            <ImageView android:id="@+id/browse_item_to_submenu"
                android:src="@drawable/icon" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_toLeftOf="@id/browse_item_add_button">
            </ImageView>

            <ImageView android:id="@+id/browse_item_row_icon"
                android:src="@drawable/icon" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_toLeftOf="@id/browse_item_to_submenu">
            </ImageView>

            <TextView android:id="@+id/browse_item_row_text"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textSize="24dp" android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:text="ABCDEFGHIJKLMNOPQRSTUVWXYZ">
            </TextView>
        </RelativeLayout>
    </FrameLayout>
</RelativeLayout>

关于android - Android Listview中重叠文本和图像的图层顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7419756/

相关文章:

android - 单选按钮在分段 ListView 滚动时更改状态

java - 复选框取消选中, ListView 的行值不会更新

android - 旋转 Android ImageView 及其背景

android - 如何在Android ImageView 上设置默认加载动画

添加 ImageLoader 时 getInstance(this) 中的 Android Volley 错误

android - 从快照启动的android模拟器中没有声音

android - 可点击的 ImageView 位置随动画变化 - android

android - 从facebook android SDK获取相册ID?

java - 我的搜索 View /过滤器在输入内容时不执行任何操作

Android Studio XML - 如何在按钮前获取 ImageView ?