[英]TextView and ListView in Relative Layout
我正在嘗試設置一個相對布局,屏幕頂部有一個工具欄,中間有一個 listView。 這是我的 xml:
<?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">
<TextView
android:id="@+id/textList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/my_toolbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="-48dp" />
<ListView
android:id="@+id/android:list"
android:layout_width="fill_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"
android:elevation="4dp"/>
</RelativeLayout>
這是在 Android Studio 中集成的編輯器中的樣子:
我已經檢查過並且列表中有一個元素,但是當我嘗試打開它時,這是我在應用程序中看到的:
會不會是與 TextView/ListView 大小有關的問題?
在您的布局中, ListView
使用了所有空間,因為它沒有像android:layout_below="@id/textList"
這樣的約束。
你可以使用這樣的東西:
<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"
android:elevation="4dp"/>
<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:text="test"/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/textList"/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.