Android HorizontalScrollView 或者 ScrollView 子项可滚动状态下遇到尾部显示不全问题解决

本文探讨了HorizontalScrollView在Android布局中的应用技巧,指出其子项使用layout_margin属性可能导致的显示问题,并提供了解决方案,建议在HorizontalScrollView外部进行变相处理或选用其他组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HorizontalScrollView为例

  <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="10dp"
        android:background="@color/green">
        <LinearLayout
            android:layout_margin="10dp" 
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/windowBackground"
            android:orientation="horizontal">
     <!-- 内容代码生成 -->

	</LinearLayout>
  </HorizontalScrollView>

1、下面是子项不足以滚动没问题
在这里插入图片描述

2、下图示意子项长度很长后 拉倒最有端 末端缺少 1 竖 灰色

在这里插入图片描述

3、修改布局去掉

android:layout_margin="10dp" 

即可

在这里插入图片描述

4、结论:HorizontalScrollView 、ScrollView 子项不要用 layout_margin 属性,在 HorizontalScrollView 、ScrollView 上面做变相处理实现对应需求,或者改用别的组件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值