gpt4 book ai didi

Android:创建多列按钮,每个按钮都有独立的 ScrollView

转载 作者:行者123 更新时间:2023-11-29 00:32:45 27 4
gpt4 key购买 nike

这是我编写的示例 XML。我正在尝试制作一个垂直对齐的按钮列表,以及另外 2 列这样的按钮。所以总共会有 3 列。每列都可以垂直滚动。如何添加更多列并使它们单独滚动?

我已经搜索并尝试了其他几种变体;我能得到的最接近的是表格布局,但垂直滚动似乎不可能!

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*">

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1"/>

<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button2"/>
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button3"/>

</TableLayout>

最佳答案

您可以使用一个水平的 LinearLayout 作为根容器,然后为每一列使用一个 ScrollView,宽度相等并包含一个垂直的 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="horizontal" >

<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<Button
android:id="@+id/button1_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />

<Button
android:id="@+id/button1_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />

<Button
android:id="@+id/button1_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />
</LinearLayout>
</ScrollView>

<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<Button
android:id="@+id/button2_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />

<Button
android:id="@+id/button2_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />

<Button
android:id="@+id/button2_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />
</LinearLayout>
</ScrollView>

<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<Button
android:id="@+id/button3_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />

<Button
android:id="@+id/button3_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />

<Button
android:id="@+id/button3_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button1" />
</LinearLayout>
</ScrollView>

关于Android:创建多列按钮,每个按钮都有独立的 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14395848/

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