我使用此 XML 在底部显示一个 Button
,在顶部显示一个 TextView
,在中间显示一个 TextView
。中间的 TextView 覆盖了按钮和顶部 TextView 之间的整个范围。中间的 TextView
根本没有显示。怎么了?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/task"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/tasks"
/>
<Button
android:id="@+id/btnAddTask"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/AddTasks"
android:layout_alignParentBottom="true"
/>
<TextView
android:id="@+id/TasksList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/tasks"
android:layout_above="@id/task"
android:layout_below="@id/btnAddTask"
/>
</RelativeLayout>
最佳答案
您的问题肯定是按钮下方有 TasksList TextView。交换您的layout_above 和layout_below 值。这对我有用:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/task"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/tasks"
/>
<Button
android:id="@+id/btnAddTask"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/AddTasks"
android:layout_alignParentBottom="true"
/>
<TextView
android:id="@+id/TasksList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/tasks"
android:layout_above="@id/btnAddTask"
android:layout_below="@id/task"
/>
</RelativeLayout>
关于android - 相对布局,Textview 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6347189/