【问题标题】:Cannot make widgets scrollable无法使小部件可滚动
【发布时间】:2018-10-07 18:19:39
【问题描述】:

我想创建一个图像按钮列表,我添加了 3 个,但只有两个是可见的,我想让它们可滚动。我尝试使用 ScrollView 但它仍然不起作用。我还尝试用 ScrollView 替换第一行中的 RelativeLayout,但应用程序开始崩溃。

这是 xml 文件:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back"
tools:context=".home">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/download"
            android:layout_gravity="center_horizontal"
            />

    </RelativeLayout>

</ScrollView>

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="230dp">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/geo" />
    </RelativeLayout>

</ScrollView>

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="4300dp">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/images"
            android:contentDescription="TODO" />

    </RelativeLayout>

</ScrollView>

【问题讨论】:

标签: android layout widget scrollview imagebutton


【解决方案1】:

将第一个滚动视图的宽度和高度作为包装内容。如果它不起作用,那么 只制作一个滚动视图。然后制作一个线性布局作为其子布局,并在具有垂直方向的线性布局中添加您的 3 个图像按钮。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多