简体   繁体   English

如何将RelativeLayout的内容对齐到ImageView的右侧?

[英]How to align the content of a RelativeLayout to the right of an ImageView?

I'm trying to create an item_view layout to inflate in a ListView, which appears as shown at the following link: Layout example . 我正在尝试创建item_view布局以在ListView中充气,该外观如以下链接所示: Layout example

The main RelativeLayout contains an ImageView and another RelativeLayout: 主RelativeLayout包含一个ImageView和另一个RelativeLayout:

<ImageView
    android:id="@+id/outbox_message_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="2dp"
    android:adjustViewBounds="true"
    android:src="@drawable/ic_action_favorite" />

On the right of the ImageView I have this RelativeLayout which contains the two textField: 在ImageView的右侧,我有这个RelativeLayout,其中包含两个textField:

<RelativeLayout
        android:id="@+id/outbox_message_info_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignBottom="@+id/outbox_message_icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/outbox_message_icon" >

        <View
            android:id="@+id/separator"
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:background="#000000" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/separator"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="TextView1" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/separator" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="TextView2" />

        </RelativeLayout>
    </RelativeLayout>

but I obtain this result: layout results . 但我得到以下结果: 布局结果 I have no idea why I obtain the correct result. 我不知道为什么我得到正确的结果。 Can anyone help me? 谁能帮我? Thanks. 谢谢。

You can use a LinearLayout for your TextViews and divider as bellow. 您可以将LinearLayout用于TextViews和分隔线。 Just change back the image to your image. 只需将图像更改回您的图像即可。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/outbox_message_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="2dp"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher" />
    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/outbox_message_info_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_alignBottom="@+id/outbox_message_icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/outbox_message_icon" >


        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="TextView1" />

        <View
            android:id="@+id/separator"
            android:layout_width="wrap_content"
            android:layout_height="1dip"
            android:layout_centerVertical="true"
            android:background="#000000" />
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="TextView2" />
    </LinearLayout>
</RelativeLayout>

This is the result: 结果如下: 预习

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM