关于android 布局中的滚动条实现
最近关于android的布局需要实现一个功能就是能够实现水平和垂直滚动,关于这个问题解决方案如下:
- 在线性布局中进行嵌套,以列为主;
- 在设计好的布局的外层进行滚动条设置;
首先将进行行列的设计,尽量多的让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

本文探讨了在Android线性布局中如何实现滚动效果,通过布局嵌套以列为主,并在外层设置滚动条,详细阐述了实现滚动功能的方法。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



