android - 在RelativeLayout布局中layout_above不起作用
PHP中文网
PHP中文网 2017-04-17 15:57:08
0
3
1327

布局文件代码如下:
layout_above没有起作用,listview把textview覆盖了

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

    <ListView
        android:id="@+id/listView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/listView2"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="20dp"
        android:text="TextView" />

</RelativeLayout>

但是在listview中添加属性android:layout_below="@+id/textView1"就没有问题

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
Peter_Zhu

Becausewrap_contentListView是不起效的,还是会撑满整个屏幕高度,先写的ListView,屏幕已经无空间了,再加TextView自然是看不见的(而不是覆盖)。还有,严谨的相对id写法应该是android:layout_below="@id/textView1"

洪涛

You can do this:

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

    <ListView
        android:layout_below="@id/textView1"
        android:id="@+id/listView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_margin="20dp"
        android:text="TextView" />

</RelativeLayout>
PHPzhong

The view tree draws views from outside to inside and from top to bottom. The measurement and layout methods of the former will affect the latter, so the dependencies should be placed in the previous view to constrain them.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template