【问题标题】:Layer order of overlapping text and image in Android ListviewAndroid Listview中重叠文本和图像的层顺序
【发布时间】:2011-09-14 16:30:32
【问题描述】:

[已更新,因为我显然还不能回答我自己的问题:它就像重新排序视图一样简单。我把 TextView 放在最后,表示 layout_alignParentLeft="true",它就成功了。]

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

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

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

有没有办法指示视图的上/下顺序?

<?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 后面有一个 imageview 吗?
  • @suri,是的。正如我在我的 [更新] 中指出的那样,我只需将 textview 移动到布局的末尾并确保它 alignsleft 就可以完成它(这是以前在开始时假设的)。
  • 嗯,你检查我的答案了吗...?
  • @suri,没有。如前所述,我回答了我自己的问题,并且我不想在不需要时添加 FrameLayout。感谢您的帮助!

标签: android listview imageview layer


【解决方案1】:

好吧,如果你想要 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>

【讨论】:

    【解决方案2】:

    使用

    使 texview 背景透明
    android:background="#0000"
    

    我认为它应该可以完成这项工作。

    【讨论】:

    • 就我而言,图像挡住了文字,我想看文字。让它(现在)覆盖图像为我提供了空间,并且仍然可以(某种程度上)看到图像。
    猜你喜欢
    • 2011-12-13
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    相关资源
    最近更新 更多