<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>
有时候 ScrollView 的实际内容不够,又想让它充满屏幕,如果laout_height 属性赋值为match_parent,那么如果还是不会充满,正确的做法是再增加一行 fillViewport的属性设置
android:layout_height="match_parent" android:fillViewport="true"
Android 滚动视图
最新推荐文章于 2024-06-24 10:48:31 发布