多級分類選單的實現
阿新 • • 發佈:2019-01-22
專案需要在商品分類頁面生成多層選單在網上搜了很多例子然後自己總結了一下寫下來備用
專案技術:Gson解析
ListView與gridview相互巢狀
多層解析json
Picasso圖片載入框架
此專案為三層分類,首先通過Gson解析獲得第一層分類資料,介面比較簡單Gson解析中使用了泛型,上程式碼:
介面形式
Gson解析過程
選單介面
實體類
gson解析第一層資料之後實現第一層選單的OnItemClickListener得到第二層資料
第二層選單使用的是listview巢狀gridview實現的
為了避免滑動衝突的問題這裡重寫gridview
二層選單的item佈局
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" >
<RelativeLayout
android:id="@+id/rl1"
android:layout_width="fill_parent"
android:layout_height ="wrap_content" >
<TextView
android:id="@+id/sort_tv_name_listandgridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="特色分類"
android:textColor="#444444"
android:textSize="16sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl1"
android:paddingRight="25dp"
>
<zhaozhipeng.webview.utils.MyGridVeiw
android:id="@+id/sort_list_gv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:horizontalSpacing="2dp"
android:listSelector="@null"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" >
</zhaozhipeng.webview.utils.MyGridVeiw>
</RelativeLayout>
</RelativeLayout>
在介面卡中得到第三層資料