您的位置:首页 > 移动开发 > Android开发

Android 滚动视图

2018-01-31 22:47 155 查看
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//水平滚动
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="200dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<View
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="#aaffff"/>
<View
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="#ffff00"/>
</LinearLayout>
</HorizontalScrollView>
//垂直滚动
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#00ff00"/>
<View
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#ffffaa"/>

</LinearLayout>
</ScrollView>

</LinearLayout>[/code]


有时候 ScrollView 的实际内容不够,又想让它充满屏幕,如果laout_height 属性赋值为match_parent,那么如果还是不会充满,正确的做法是再增加一行 fillViewport的属性设置

android:layout_height="match_parent"
android:fillViewport="true"[/code]




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android