开发者

Layer order of overlapping text and image in Android Listview

开发者 https://www.devze.com 2023-04-05 09:09 出处:网络
[Updated, as I apparently can\'t answer my own question yet:It\'s as simple as re-ordering the views.I put the TextView at the end, indicated layout_alignParentLeft=\"true\", and it does the trick.]

[Updated, as I apparently can't answer my own question yet: It's as simple as re-ordering the views. I put the TextView at the end, indicated layout_alignParentLeft="true", and it does the trick.]

I have a typical ListView item description, with text and images (3) in each row.

I noticed that the image (id="@+id/browse_item_row_icon") on the right side of the row was drawn on top of (over) the text.

While not immediately what I wanted, I decided it would actually work, IF I could have that image behind the text instead of on top of it. This would allow me to display more text if necessary, and covering up part of the image will not impact usability.

Is there a way to indicate above/below ordering of views?

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


Well, in your case if you want images behind the TextView you can use FrameLayout for that, try this.

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


make the texview background transparent, by using

android:background="#0000"

I think it should do the job.

0

精彩评论

暂无评论...
验证码 换一张
取 消