Android GridView簡(jiǎn)單實(shí)例
也是今天用到的一個(gè)東西,就是簡(jiǎn)單實(shí)現(xiàn)九宮格的Demo
1.就是定義各種layout 和對(duì)應(yīng)的item
我的:
<?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:background="#fff" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <GridView android:id="@+id/gridView" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="3" android:background="#fff"></GridView> </LinearLayout> </LinearLayout>
itme的
<?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:padding="10dp" android:layout_gravity="center" android:background="#fff" android:orientation="vertical" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv" android:paddingTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000" android:text="管線" /> </LinearLayout>
開始準(zhǔn)備數(shù)據(jù):
/** * 準(zhǔn)備顯示的數(shù)據(jù) */ public void initData() { // 生成動(dòng)態(tài)數(shù)組,并且轉(zhuǎn)入數(shù)據(jù) ,暫時(shí)就這樣來處理 lstImageItem = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < 3; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("ItemImage", R.drawable.osg);// 添加圖像資源的ID map.put("ItemText", "各種管線" + String.valueOf(i));// 按序號(hào)做ItemText lstImageItem.add(map); } }
設(shè)置顯示
gv = (GridView) view.findViewById(R.id.gridView); SimpleAdapter adapter = new SimpleAdapter(this, lstImageItem, R.layout.gridview_item, new String[] { "ItemImage", "ItemText" }, new int[] { R.id.iv, R.id.tv }); gv.setAdapter(adapter);
最后扔一張效果圖
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android中GridView實(shí)現(xiàn)點(diǎn)擊查看更多功能示例
- Android中控件GridView實(shí)現(xiàn)設(shè)置行列分割線的方法示例
- Android使用GridView實(shí)現(xiàn)日歷功能示例(詳細(xì)代碼)
- Android使用GridView實(shí)現(xiàn)日歷的簡(jiǎn)單功能
- Android自定義DataGridView數(shù)據(jù)表格控件
- Android 利用ViewPager+GridView實(shí)現(xiàn)首頁(yè)導(dǎo)航欄布局分頁(yè)效果
- Android 中 GridView嵌套在ScrollView里只有一行的解決方法
- Android GridView實(shí)現(xiàn)動(dòng)畫效果實(shí)現(xiàn)代碼
相關(guān)文章
Android仿微信菜單(Menu)(使用C#和Java分別實(shí)現(xiàn))
這篇文章主要介紹了Android仿微信菜單(Menu)(使用C#和Java分別實(shí)現(xiàn)),本文分別給出C#和Java版的運(yùn)行效果及實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-06-06Jetpack Compose實(shí)現(xiàn)列表和動(dòng)畫效果詳解
這篇文章主要為大家詳細(xì)講講Jetpack Compose實(shí)現(xiàn)列表和動(dòng)畫效果的方法步驟,文中的代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-06-06Android Studio下添加assets目錄的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狝ndroid Studio下添加assets目錄的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03Android RefreshLayout實(shí)現(xiàn)下拉刷新布局
這篇文章主要為大家詳細(xì)介紹了Android RefreshLayout實(shí)現(xiàn)下拉刷新布局,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android WebView如何判斷是否滾動(dòng)到底部
大家好,本篇文章主要講的是Android WebView如何判斷是否滾動(dòng)到底部,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01Android TextView前增加紅色必填項(xiàng)星號(hào)*的示例代碼
TextView是一個(gè)完整的文本編輯器,但是基類為不允許編輯,其子類EditText允許文本編輯,這篇文章主要介紹了Android TextView前增加紅色必填項(xiàng)星號(hào)*的示例代碼,需要的朋友可以參考下2024-03-03Android自定義下拉刷新控件RefreshableView
這篇文章主要介紹了Android自定義下拉刷新控件RefreshableView,支持所有控件的下拉刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11Android 桌面快捷方式實(shí)現(xiàn)實(shí)例詳解
這篇文章主要為大家介紹了Android 桌面快捷方式實(shí)現(xiàn)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11Android實(shí)現(xiàn)搜索保存歷史記錄功能
這篇文章主要介紹了Android實(shí)現(xiàn)搜索保存歷史記錄功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05