如何在另一个RelativeLayout的RelativeLayout中定位TextView?

时间:2013-05-15 11:29:13

标签: android android-layout relativelayout

我遇到这个问题,我需要在RelativeLayout(黑色)下面的RelativeLayout(蓝色)内放置TextView(绿色),但ImageView(橙色)保持重叠

enter image description here

这是传说:

  • RelativeLayout(黑色)id / image_view_container
  • ImageView的(褐色)
  • RelativeLayout的(蓝色)
  • ImageView(橙色)id / profileImage
  • TextView的(绿色)

我试过了:

android:layout_toRightOf="@id/profileImage"
android:layout_below="@id/image_view_container"

但它不起作用,可能是因为image_view_container来自另一个RelativeLayout。

我需要这方面的帮助,谢谢!

编辑:

    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/image_view_container" >
                <ImageView
                    android:id="@+id/mainImage"
                    android:layout_width="fill_parent"
                    android:layout_height="210dp" 
                    android:background="#ffffff"
                    />
    </RelativeLayout>
<RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-30dp"
            android:gravity="bottom"
            android:orientation="horizontal" >
            <ImageView
                android:id="@+id/profileImage"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginLeft="20dp"
                android:layout_weight="0"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:scaleType="centerCrop"
                />

            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_below="@id/image_view_container"
                android:layout_toRightOf="@id/profileImage"
                android:layout_weight="1"
                android:text="6363"
                android:textColor="@color/A"
                android:textSize="20sp"
                android:textStyle="bold"
                android:translationY="5dp" />
        </RelativeLayout>

2 个答案:

答案 0 :(得分:0)

image_view_container

中尝试以下操作
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

答案 1 :(得分:0)

试试这个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:id="@+id/image_view_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff00ff" >

    <ImageView
        android:id="@+id/mainImage"
        android:layout_width="fill_parent"
        android:layout_height="310dp"
        android:layout_margin="20dp"
        android:background="#ffff00" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/image_view_container"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/profileImage"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_weight="0"
        android:background="#ff1234"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/profileImage"
        android:layout_toRightOf="@id/profileImage"
        android:layout_weight="1"
        android:text="6363"
        android:background="#ff0034"
        android:textSize="20sp"
        android:textStyle="bold" />
</RelativeLayout>

相关问题