android - 无法使小部件可滚动
问题描述
我想创建一个图像按钮列表,我添加了 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>
解决方案
将第一个滚动视图的宽度和高度设置为包装内容。如果它不起作用,则只制作一个滚动视图。然后将线性布局作为其子级,并在具有垂直方向的线性布局中添加 3 个图像按钮。
推荐阅读
- aws-cloudwatch-log-insights - AWS Cloudwatch Insights:如何按计数聚合(*)
- google-api - 修改日历信息(名称、描述等)后 Google 日历 ETag 未更新
- pouchdb - 如何取消一次性复制
- php - 将数组导出到 XML 文件 - utf-8 编码问题
- java - Spring Factory 方法“jdbcTemplate”抛出异常;属性“数据源”是必需的
- r - 如何在 ggplot2 中应用 after_stat 和 faceting?
- c# - 通过对重复信息进行分组从列表中创建对象
- c++ - return r 总是有效的吗?
- java - 找不到 io.spring.gradle:propdeps-plugin:0.0.9.RELEASE
- python - 将网站表格转换为 pandas df(beautifulsoup 无法识别表格)