gpt4 book ai didi

android - 相对布局中的 TextView 和 ListView

转载 作者:行者123 更新时间:2023-11-29 22:54:19 25 4
gpt4 key购买 nike

我正在尝试设置一个相对布局,在屏幕顶部有一个工具栏,在中心有一个 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 中集成的编辑器中的样子: enter image description here

我已经检查过列表中有一个元素,但是当我尝试打开它时,我在应用程序中看到的是: prova

会不会是TextView/ListView大小的问题?

编辑:这是修改 xml 后的样子: enter image description here

最佳答案

在您的布局中,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>

关于android - 相对布局中的 TextView 和 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57596842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com