关于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_width="100dp" android:layout_height="60dp"/>