无法使小部件可滚动
Cannot make widgets scrollable
我想创建一个图像按钮列表,我添加了其中的 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>
将第一个滚动视图的宽度和高度设置为包装内容。如果它不起作用则
仅制作一个滚动条 view.Then 将线性布局作为其子布局,并在具有垂直方向的线性布局中添加 3 个图像按钮。
我想创建一个图像按钮列表,我添加了其中的 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>
将第一个滚动视图的宽度和高度设置为包装内容。如果它不起作用则 仅制作一个滚动条 view.Then 将线性布局作为其子布局,并在具有垂直方向的线性布局中添加 3 个图像按钮。