最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

九宮圖比較常用的多控件布局(GridView)使用介紹

 更新時間:2013年06月19日 15:21:44   作者:  
GridView跟ListView都是比較常用的多控件布局,而GridView更是實現九宮圖的首選,下面與大家分享下GridView用法,感興趣的朋友可以參考下哈
GridView跟ListView都是比較常用的多控件布局,而GridView更是實現九宮圖的首選!本文就是介紹如何使用GridView實現九宮圖。GridView的用法很多,網上介紹最多的方法就是自己實現一個ImageAdapter繼承BaseAdapter,再供GridView使用,類似這種的方法本文不再重復,本文介紹的GridView用法跟前文ListView的極其類似。也算是我偷懶一下,嘻嘻嘻嘻。。。。

先來貼出本文代碼運行的結果:
 
本文需要添加/修改3個文件:main.xml、night_item.xml、JAVA源代碼。
main.xml源代碼如下,本身是個GirdView,用于裝載Item:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

介紹一下里面的某些屬性:
android:numColumns="auto_fit" ,GridView的列數設置為自動

android:columnWidth="90dp",每列的寬度,也就是Item的寬度
android:stretchMode="columnWidth",縮放與列寬大小同步
android:verticalSpacing="10dp",兩行之間的邊距,如:行一(NO.0~NO.2)與行二(NO.3~NO.5)間距為10dp
android:horizontalSpacing="10dp",兩列之間的邊距。

接下來介紹 night_item.xml,這個XML跟前面ListView的ImageItem.xml很類似:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:paddingBottom="4dip" android:layout_width="fill_parent">
<ImageView
android:layout_height="wrap_content"
android:id="@+id/ItemImage"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_below="@+id/ItemImage"
android:layout_height="wrap_content"
android:text="TextView01"
android:layout_centerHorizontal="true"
android:id="@+id/ItemText">
</TextView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:paddingBottom="4dip" android:layout_width="fill_parent">
<ImageView
android:layout_height="wrap_content"
android:id="@+id/ItemImage"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_below="@+id/ItemImage"
android:layout_height="wrap_content"
android:text="TextView01"
android:layout_centerHorizontal="true"
android:id="@+id/ItemText">
</TextView>
</RelativeLayout>

最后就是JAVA的源代碼了,也跟前面的ListView的JAVA源代碼很類似,不過多了“選中”的事件處理:
復制代碼 代碼如下:

view plaincopy to clipboardprint?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);

//生成動態(tài)數組,并且轉入數據
ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
for(int i=0;i<10;i++)

相關文章

  • PHP autoload 機制詳解

    PHP autoload 機制詳解

    本文主要介紹 PHP autoload 機制,這里整理了詳細的知識資料供大家學習參考,希望能幫助有需要的小伙伴
    2016-08-08
  • Android使用socket創(chuàng)建簡單TCP連接的方法

    Android使用socket創(chuàng)建簡單TCP連接的方法

    這篇文章主要介紹了Android使用socket創(chuàng)建簡單TCP連接的方法,結合實例形式詳細分析了Android使用socket創(chuàng)建TCP連接的具體步驟與實現技巧,需要的朋友可以參考下
    2016-04-04
  • Android開發(fā)實現SubMenu選項菜單和子菜單示例

    Android開發(fā)實現SubMenu選項菜單和子菜單示例

    這篇文章主要介紹了Android開發(fā)實現SubMenu選項菜單和子菜單,結合實例形式分析了Android開發(fā)中SubMenu選項菜單和子菜單的功能、配置、布局等相關操作技巧,需要的朋友可以參考下
    2019-03-03
  • Android內存使用情況的應用實例

    Android內存使用情況的應用實例

    這篇文章主要介紹了Android內存使用情況的應用實例的相關資料,需要的朋友可以參考下
    2017-04-04
  • Android平臺下輕量級http網絡傳輸庫

    Android平臺下輕量級http網絡傳輸庫

    這篇文章主要介紹了Android平臺下輕量級http網絡傳輸庫的相關資料,需要的朋友可以參考下
    2016-01-01
  • 詳細講解AsyncTask使用說明(值得收藏)

    詳細講解AsyncTask使用說明(值得收藏)

    AsyncTask就相當于Android給我們提供了一個多線程編程的一個框架,其介于Thread和Handler之間,我們如果要定義一個AsyncTask,就需要定義一個類來繼承AsyncTask這個抽象類,并實現其唯一的一doInBackgroud 抽象方法,這篇文章主要介紹了AsyncTask詳解,需要的朋友可以參考下
    2024-01-01
  • 淺談Android官方MVP架構解讀

    淺談Android官方MVP架構解讀

    這篇文章主要介紹了淺談Android官方MVP架構解讀,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • Android開發(fā)中RecyclerView組件使用的一些進階技講解

    Android開發(fā)中RecyclerView組件使用的一些進階技講解

    RecyclerView是Android 5.0以來新加入的一個組件,基本上全面優(yōu)于ListView,這里我們將來關注Android開發(fā)中RecyclerView組件使用的一些進階技講解:
    2016-06-06
  • Android仿IOS自定義AlertDialog提示框

    Android仿IOS自定義AlertDialog提示框

    本篇文章主要介紹了Android仿IOS自定義AlertDialog對話框,主要介紹了圓角AlertDialog對話框,具有一定的參考價值,有興趣的可以了解一下。
    2017-03-03
  • Android studio 實現手機掃描二維碼功能

    Android studio 實現手機掃描二維碼功能

    這篇文章主要介紹了Android studio 實現手機掃描二維碼功能,需要的朋友可以參考下
    2019-10-10

最新評論

邯郸市| 洛隆县| 阳信县| 精河县| 广德县| 金坛市| 青阳县| 扬州市| 菏泽市| 芦溪县| 烟台市| 余姚市| 家居| 新乐市| 台南县| 孟连| 西城区| 前郭尔| 山丹县| 南充市| 新泰市| 固阳县| 延长县| 和平县| 赣榆县| 渭南市| 宁南县| 龙江县| 定边县| 宜都市| 运城市| 高陵县| 开平市| 东乡| 通河县| 凤山县| 潜山县| 罗平县| 微山县| 平武县| 扎赉特旗|