【问题标题】:How to position a TextView inside a RelativeLayout from another RelativeLayout?如何从另一个RelativeLayout 将TextView 定位在RelativeLayout 中?
【发布时间】:2013-05-15 20:56:54
【问题描述】:

我遇到了这个问题,我需要将 TextView(green) 放在 RelativeLayout(blue) 下面的 RelativeLayout(black) 但 ImageView(orange) 保持重叠

这是传说:

  • RelativeLayout(black) id/image_view_container
  • ImageView(棕色)
  • 相对布局(蓝色)
  • 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>

【问题讨论】:

  • 请发布完整的 xml,好像你的蓝色相对布局容器不合适
  • 你如何包含另一个布局?
  • 请发布您的整个 XML 文件...
  • 只有在有背景的情况下才需要蓝色,即使那样,绿色和橙色也不需要在其中(可以与黑色在相同的RelativeLayout中)
  • 我试图通过两个RelativeLayouts 做到这一点,但没有运气。多亏了这个!直到现在我还没有想到。我可以将橙色和绿色封装在同一个 RelativeLayout 下。

标签: android android-layout android-relativelayout


【解决方案1】:

在您的 image_view_container 中尝试以下操作

android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

【讨论】:

    【解决方案2】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多