关于Android线性布局与滚动实现

本文探讨了在Android线性布局中如何实现滚动效果,通过布局嵌套以列为主,并在外层设置滚动条,详细阐述了实现滚动功能的方法。
摘要由CSDN通过智能技术生成

关于android 布局中的滚动条实现

最近关于android的布局需要实现一个功能就是能够实现水平和垂直滚动,关于这个问题解决方案如下:
  1. 在线性布局中进行嵌套,以列为主;
  2. 在设计好的布局的外层进行滚动条设置;
首先将进行行列的设计,尽量多的让btn比手机的像素值大这样才能够进行滚动。
相关代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <HorizontalScrollView android:layout_width="match_parent"
                          android:layout_height="match_parent">
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
            <LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content">
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
            </LinearLayout>

            <LinearLayout android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content">
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
                <Button android:layout_width="100dp" android:layout_height="60dp"/>
              
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值