gpt4 book ai didi

java - 使屏幕按钮可滚动

转载 作者:行者123 更新时间:2023-12-01 14:43:21 24 4
gpt4 key购买 nike

我的屏幕有 18 个按钮,是否可以使这组按钮可滚动,以便用户可以看到不在可视区域的按钮。我尝试将这些按钮放入 ScrollView 中,但得到的异常(exception)是它们只能是 ScrollView 的 1 个子级。

目前,按钮出现在relativelayout中,如下所示:

<Button
android:id="@+id/btnChapter2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnChapter1"
android:layout_below="@+id/btnChapter1"
android:text="Chapter 2" />

<Button
android:id="@+id/btnChapter3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnChapter2"
android:layout_below="@+id/btnChapter2"
android:text="Chapter 3" />

<Button
android:id="@+id/btnChapter4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnChapter3"
android:layout_below="@+id/btnChapter3"
android:text="Chapter 4" />

<Button
android:id="@+id/btnChapter5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnChapter4"
android:layout_below="@+id/btnChapter4"
android:text="Chapter 5" />

<Button
android:id="@+id/btnChapter6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnChapter5"
android:layout_below="@+id/btnChapter5"
android:text="Chapter 6" />

当前屏幕上的按钮 9、17 和 18 被搞砸了,如下所示:

enter image description here

最佳答案

嗯,ScrollView 可能只有一个 child 。在这种情况下,将 LinearLayout 或relativelayout 作为 ScrollView 的子级。将按钮放入 LinearLayout 或relativelayout 中。那应该就可以了。示例代码:

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

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

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

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

</LinearLayout>
</ScrollView>

关于java - 使屏幕按钮可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15721081/

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