横向 gridView 一行 滚动

引用:http://www.eoeandroid.com/thread-14382-2-1.html

<HorizontalScrollView android:id="@+id/hsView"
        android:layout_width="fill_parent" android:layout_height="wrap_content" 
        android:visibility="gone"  android:background="#E9E9E9">
            <LinearLayout
                android:layout_width="fill_parent"  android:layout_height="wrap_content" 
                android:orientation="horizontal">
                <GridView  android:id="@+id/gridView"
                    android:layout_width="fill_parent" android:layout_height="wrap_content" />
            </LinearLayout>
    </HorizontalScrollView>
----------------------------------------------------------------------
MainActivity.java

  LayoutParams params = new LayoutParams(videoList.size() * (columnWidth+horizontalSpacing),LayoutParams.WRAP_CONTENT);
    gridView.setLayoutParams(params);    //gridView的整体宽度
    gridView.setColumnWidth(360);   //列宽(像素)
    gridView.setHorizontalSpacing(4);  //水平间距
    gridView.setStretchMode(GridView.NO_STRETCH);   //不拉伸
    gridView.setNumColumns(videoList.size());      //一排显示几列

原文地址:https://www.cnblogs.com/sode/p/2177735.html