简体   繁体   English

Layout_below在RelativeLayout中不起作用

[英]Layout_below does not work in RelativeLayout

I'm pretty new to Android development. 我是Android开发的新手。
I'm using the following RelativeLayout. 我正在使用以下RelativeLayout。
I want my txtView1 to be above lstAnswers, but layout_below doesn't work and the views are overlayed. 我希望我的txtView1在lstAnswers之上,但是layout_below不起作用,并且视图被覆盖了。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:background="#ffbad6e6"
                tools:context="com.example.user.myApp.QuestionDetails">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/txtView1"
        android:textColor="#ff0d5e52"/>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/lstAnswers"
        android:layout_centerHorizontal="false"
        android:paddingTop="50dp"
        android:layout_alignParentTop="true"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        android:layout_below="@id/txtView1"/>

</RelativeLayout>

I also tried to set layout_below using @+id, like this: 我还尝试使用@ + id设置layout_below,如下所示:

android:layout_below="@+id/txtView1"

but that gave me nothing. 但这什么也没给我。
Can anybody explain me how can I set txtView1 above lstAnswers? 谁能解释我如何在lstAnswers上方设置txtView1?

Very easy. 很容易。

Remove android:layout_alignParentTop="true" from your ListView. 从您的ListView中删除android:layout_alignParentTop="true"
So, android:layout_below="@id/txtView1" will be able to do its job. 因此, android:layout_below="@id/txtView1"将能够完成其工作。

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

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