【问题标题】:Can't get RelativeLayout to set above another RelativeLayout?无法将 RelativeLayout 设置在另一个 RelativeLayout 之上?
【发布时间】:2016-07-19 12:00:17
【问题描述】:

XML:

<?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"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/sendToLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:orientation="vertical"
    android:background="#292929" >
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Contacts"
    android:layout_marginTop="10dp"
    android:layout_marginRight="5dp" />


<EditText
    android:id="@+id/sendToType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/button1"
    android:ems="10"
    android:layout_margin="10dp"
    android:hint="To" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/previewlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/sendToLayout"
    android:orientation="vertical" >

    <TextView 
        android:id="@+id/preview"
        android:text="Message Preview: "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textColor="#ffffff"
        android:layout_marginTop="5dp"

        />



    <RelativeLayout
        android:id="@+id/previewLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/preview"
        android:layout_marginTop="5dp"
        android:background="@drawable/bg"
        android:layout_above="@+id/messageLayout" >

        <TextView 
        android:id="@+id/messagePreview"
        android:text="Message Preview will be shown here"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#b5b5b5"
        />
    </RelativeLayout>

</RelativeLayout>

<RelativeLayout
    android:id="@+id/messageLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">
<Button
    android:id="@+id/addNumberButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/messageLayout3"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="5dp"
    android:text="Contacts" />



<EditText
    android:id="@+id/enterMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignBottom="@+id/messageLayout3"
    android:layout_toLeftOf="@+id/addNumberButton"
    android:ems="10"
    android:layout_marginTop="5dp"
    android:hint="Message" />

</RelativeLayout>

突出显示的RelativeLayout (@+id/previewLayout)

应该只到thisRelativeLayout(@+id/messageLayout)的顶部:

但它一直到屏幕/父级的底部。我做错了什么?

【问题讨论】:

  • 尝试将第一个RelativeLayout的高度更改为固定大小,并检查它是否有效。

标签: android android-layout layout android-relativelayout


【解决方案1】:

将此行放在您的@+id/previewlayout 相对布局节点中..

 android:layout_above="@+id/messageLayout"

【讨论】:

  • 不敢相信我错过了。谢谢
【解决方案2】:
<?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"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/sendToLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:orientation="vertical"
    android:background="#292929" >
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Contacts"
    android:layout_marginTop="10dp"
    android:layout_marginRight="5dp" />


<EditText
    android:id="@+id/sendToType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/button1"
    android:ems="10"
    android:layout_margin="10dp"
    android:hint="To" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/messageLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">
<Button
    android:id="@+id/addNumberButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/messageLayout3"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="5dp"
    android:text="Contacts" />



<EditText
    android:id="@+id/enterMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignBottom="@+id/messageLayout3"
    android:layout_toLeftOf="@+id/addNumberButton"
    android:ems="10"
    android:layout_marginTop="5dp"
    android:hint="Message" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/previewlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_above="@+id/messageLayout"
    android:layout_below="@+id/sendToLayout"
    android:orientation="vertical" >

    <TextView 
        android:id="@+id/preview"
        android:text="Message Preview: "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textColor="#ffffff"
        android:layout_marginTop="5dp"

        />



    <RelativeLayout
        android:id="@+id/previewLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/preview"
        android:layout_marginTop="5dp"
        android:background="@drawable/bg"
        android:layout_above="@+id/messageLayout" >

        <TextView 
        android:id="@+id/messagePreview"
        android:text="Message Preview will be shown here"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#b5b5b5"
        />
    </RelativeLayout>

</RelativeLayout>

【讨论】:

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