国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 仿京東側滑篩選實例代碼

2019-12-12 03:14:17
字體:
來源:轉載
供稿:網友

簡單介紹

這個demo寫的是仿京東的側滑篩選頁面,點擊進入篩選后進入二級篩選,兩次側滑的篩選,還包括ListView+CheckBox滑動沖突,ListView+ GridView顯示一行問題解決,接口回調傳遞數據等

效果圖



簡單得代碼介紹

1.首頁側滑用的是安卓官方V4包中的DrawerLayout

<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/drawer_layout"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:fitsSystemWindows="true">  <FrameLayout    android:id="@+id/main_content"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true">    <TextView      android:id="@+id/screenTv"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:layout_gravity="center|top"      android:layout_marginTop="200dp"      android:text="仿京東篩選"      android:textSize="20sp" />  </FrameLayout>  <LinearLayout    android:id="@+id/nav_view"    android:layout_width="wrap_content"    android:layout_height="match_parent"    android:layout_gravity="end"    android:fitsSystemWindows="true"    android:orientation="vertical" /></android.support.v4.widget.DrawerLayout>

2.一級頁面是自定義的layout,作為DrawerLayout的側滑頁面添加進去

menuHeaderView = new RightSideslipLay(ScreeningActivity.this);navigationView.addView(menuHeaderView);

發現的一個小的技巧想要側滑不隨滑動而滑動,只能點擊才出現側滑的話,可以先鎖定
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);這樣就不一直跟著手勢側滑了

3.一級界面 ListVIew嵌套GridView,GridView得做自設配高度的自定義,不然只能顯示一行,具體參源碼AutoMeasureHeightGridView這個類

4.接下來是解析數據綁定數據了,還算比較簡單。定義模型類,京東的篩選默認每項顯示數據3個即一行。我現在默認的是都是關閉的,只有第一項是打開的,默認顯現9個即3行,點擊查看更多就能進入下一級頁面。參看圖二

5.二級頁面是一個PopupWindow,設置了PopupWindow的位置和動畫達到,也能像一級界面也樣,右邊側滑出來,點擊側滑收回去的效果。

/** * 創建PopupWindow */private PopupWindow mMenuPop;public RightSideslipChildLay mDownMenu;protected void initPopuptWindow(List<AttrList.Attr.Vals> mSelectData) {  mDownMenu = new RightSideslipChildLay(getContext(), ValsData, mSelectData);  if (mMenuPop == null) {    mMenuPop = new PopupWindow(mDownMenu, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);  }  mMenuPop.setBackgroundDrawable(new BitmapDrawable());  mMenuPop.setAnimationStyle(R.style.popupWindowAnimRight);  mMenuPop.setFocusable(true);  mMenuPop.showAtLocation(RightSideslipLay.this, Gravity.TOP, 100, UiUtils.getStatusBarHeight(mCtx));  mMenuPop.setOnDismissListener(new PopupWindow.OnDismissListener() {    @Override    public void onDismiss() {      dismissMenuPop();    }  });}

此頁面是一個ListView里包含CheckBox,對于CheckBox滑動選中錯位的問題在這個demo中也有解決,此法一本萬利。可以下載demo來參考。大體思路是CheckBox選中的狀態對象的存在需要顯示的對象里,設置對象的一個屬性,記錄CheckBox選中的狀態。

6.對于頁面件數據的傳遞使用的接口回調。包括Adapter數據操作的傳出和一級頁面傳入二級頁面,二級頁面在回傳給一級頁面顯示。一級頁面在傳出給主頁面(這個沒有寫)也可以用其他數據傳遞的方式,這只是方法之一。

7.項目下載地址:AndroidScreening_jb51.rar

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐亭县| 德安县| 蒙城县| 桂林市| 涿州市| 多伦县| 嘉义县| 吐鲁番市| 龙山县| 田东县| 武夷山市| 襄樊市| 石林| 修水县| 宜城市| 高清| 华安县| 罗田县| 盐池县| 五常市| 石林| 涟水县| 紫阳县| 潼南县| 通化县| 河东区| 青田县| 崇信县| 鹿泉市| 锡林郭勒盟| 西青区| 岳普湖县| 卓尼县| 青海省| 新田县| 东莞市| 廊坊市| 扶沟县| 蓬溪县| 宜兰市| 兴海县|