gpt4 book ai didi

android - 如何将两个或多个 ListView 放在同一个布局上?

转载 作者:搜寻专家 更新时间:2023-11-01 08:15:45 24 4
gpt4 key购买 nike

我试过这段代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<ListView
android:id="@+id/List1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />

<ListView
android:id="@+id/List2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />

<ListView
android:id="@+id/List3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />

<ListView
android:id="@+id/List4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

没有成功。这行得通,但我不想划分 x所有列表的屏幕,我想扩展 width每个列表的列表,并可以在 x 上滚动轴 ...有谁知道我是否可以做到这一点?

最佳答案

这是可能的。在您的情况下,它不起作用,因为 android:layout_width 设置为 fill_parent,因此第一个布局将占用所有可用空间。尝试为每个 ListView 提供 android:layout_weight="1"。并删除不需要的内部 LinearLayouts

这对我有用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<ListView
android:id="@+id/List1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />

<ListView
android:id="@+id/List2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>

我刚刚获取了您的代码并删除了两个 ListView :

enter image description here

关于android - 如何将两个或多个 ListView 放在同一个布局上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5106535/

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