我正在尝试在RelativeLayout中设置工具栏,该工具栏内部具有列表视图。问题是,一旦我将两个元素放入列表中,便是结果:
菜单选项也消失。这是我的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
style="@style/HeaderBar"/>
<TextView
android:id="@+id/textList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/my_toolbar"
android:layout_centerHorizontal="true"
android:textSize="26dp" />
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_below="@+id/my_toolbar"
android:layout_height="match_parent"/>
答案 0 :(得分:2)
更改以下行
android:layout_below="@+id/my_toolbar"
到
android:layout_below="@id/my_toolbar"
加号用于创建新资源,当我们需要引用已经创建的资源(即由android:id =“ @ + id / x”创建)时,我们不应使用+,否则将不会使用+引用正确
答案 1 :(得分:0)
只需将Listview的android:layout_below="@+id/my_toolbar"
更改为android:layout_below="@+id/textList"
答案 2 :(得分:0)
尝试使用此代码enter image description here
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
<TextView
android:id="@+id/textList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/my_toolbar"
android:layout_centerHorizontal="true"
android:textSize="26dp" />
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_below="@+id/textList"
android:layout_height="match_parent"/>