本文實(shí)例為大家分享了Android使用GridView實(shí)現(xiàn)橫向滾動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下
第一次做橫向滑動(dòng),看了一些列子,基本就2總:HorizontalListView和GridView。考慮的了下選擇用比較熟的GridView,并且在2種方案都使用過(guò),根據(jù)本人實(shí)際情況,采用了更適合的GridView。
也希望看過(guò)這篇博客的大神們,能指點(diǎn)下HorizontalListView和GridView兩個(gè)方案的優(yōu)缺點(diǎn)。
思路:
XML界面:用HorizontalScrollView + GridView 配合使用。
Java代碼部分:和普通GridView使用基本一致,但需要手動(dòng)設(shè)置GridView的width以及Item的Width等。
筆者實(shí)際情況是:左右滑動(dòng),1行以4個(gè)為基準(zhǔn)。
在不同尺寸的平板下,呈現(xiàn)都是一個(gè)界面4個(gè)Item。
先上效果圖
模擬器Nexus 10 API 18 2560x1600: xhdpi 效果如下:

模擬器Nexus 9 API 18 2048x1536: xhdpi 效果如下:

XML代碼
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <GridView android:id="@+id/dev_gv" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:numColumns="auto_fit" android:stretchMode="spacingWidthUniform"> </GridView> </LinearLayout> </HorizontalScrollView></LinearLayout>
android:numColumns=”auto_fit” 主站蜘蛛池模板: 元阳县| 娱乐| 池州市| 大英县| 蓬莱市| 商城县| 景德镇市| 鹤壁市| 东阳市| 财经| 中西区| 福州市| 宜君县| 贞丰县| 望江县| 邢台市| 台湾省| 莒南县| 铜鼓县| 镇沅| 济宁市| 万宁市| 潍坊市| 报价| 平度市| 合阳县| 克山县| 高碑店市| 津南区| 郁南县| 佳木斯市| 灵宝市| 建水县| 青川县| 大英县| 阜宁县| 错那县| 江都市| 治县。| 漠河县| 蓝田县|