某些视图未显示在 RelativeLayout 中
Some views don't show in RelativeLayout
我有以下RelativeView。我要
- 在底部编辑文本
- 顶部的 TextView - 我这里有一个问题 - 它没有显示,但我不明白为什么
- 它们之间有 2 个 ListView - 都垂直占据屏幕的一半
请问您明白为什么顶部的 TextView 不显示了吗?
<?xml version="1.0" encoding="utf-8"?>
<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">
<EditText
android:id="@+id/Search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_alignParentBottom="true">
<requestFocus />
</EditText>
<View android:id="@+id/Placeholder"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_above="@id/Search"
android:layout_centerInParent="true"/>
<ListView
android:id="@+id/ResultsColumn1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="@id/Placeholder"
android:layout_above="@id/Search" />
<ListView
android:id="@+id/ResultsColumn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@id/Placeholder"
android:layout_above="@id/Search"/>
<TextView
android:id="@+id/InformationTextTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ResultsColumn1"
android:text="Why is this not visible ?"/>
</RelativeLayout>
只是因为 ListView
在 android:layout_height
属性 中有 match_parent
并且 TextView
在 [=18= 中定义在它们之后].由于这是一个非常简单的布局,我建议改用 LinearLayout
。
<LinearLayout 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:orientation="vertical">
<TextView
android:id="@+id/InformationTextTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ResultsColumn1"
android:text="Why is this not visible ?"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ListView
android:id="@+id/ResultsColumn1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ListView
android:id="@+id/ResultsColumn2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<EditText
android:id="@+id/Search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text">
<requestFocus />
</EditText>
</LinearLayout>
我有以下RelativeView。我要
- 在底部编辑文本
- 顶部的 TextView - 我这里有一个问题 - 它没有显示,但我不明白为什么
- 它们之间有 2 个 ListView - 都垂直占据屏幕的一半
请问您明白为什么顶部的 TextView 不显示了吗?
<?xml version="1.0" encoding="utf-8"?>
<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">
<EditText
android:id="@+id/Search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_alignParentBottom="true">
<requestFocus />
</EditText>
<View android:id="@+id/Placeholder"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_above="@id/Search"
android:layout_centerInParent="true"/>
<ListView
android:id="@+id/ResultsColumn1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="@id/Placeholder"
android:layout_above="@id/Search" />
<ListView
android:id="@+id/ResultsColumn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@id/Placeholder"
android:layout_above="@id/Search"/>
<TextView
android:id="@+id/InformationTextTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ResultsColumn1"
android:text="Why is this not visible ?"/>
</RelativeLayout>
只是因为 ListView
在 android:layout_height
属性 中有 match_parent
并且 TextView
在 [=18= 中定义在它们之后].由于这是一个非常简单的布局,我建议改用 LinearLayout
。
<LinearLayout 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:orientation="vertical">
<TextView
android:id="@+id/InformationTextTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ResultsColumn1"
android:text="Why is this not visible ?"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ListView
android:id="@+id/ResultsColumn1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<ListView
android:id="@+id/ResultsColumn2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<EditText
android:id="@+id/Search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text">
<requestFocus />
</EditText>
</LinearLayout>