要想实现滚动显示,layout布局里必须要使用HorizontalScrollView,才能实现横向滑动,但HorizontalScrollView标签里要嵌套一个LinearLayout布局
activity_main.xml,如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:weightSum="2" >
<HorizontalScrollView
android:id="@+id/horizontal_scrollview"
android:layout_height="0dp"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:background="@android:color/darker_gray"
android:scrollbars="none">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal">
<GridView
android:id="@+id/test_gridview"