Android 仿京東側(cè)滑篩選實例代碼
簡單介紹
這個demo寫的是仿京東的側(cè)滑篩選頁面,點擊進入篩選后進入二級篩選,兩次側(cè)滑的篩選,還包括ListView+CheckBox滑動沖突,ListView+ GridView顯示一行問題解決,接口回調(diào)傳遞數(shù)據(jù)等
效果圖
簡單得代碼介紹
1.首頁側(cè)滑用的是安卓官方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的側(cè)滑頁面添加進去
menuHeaderView = new RightSideslipLay(ScreeningActivity.this); navigationView.addView(menuHeaderView);
發(fā)現(xiàn)的一個小的技巧想要側(cè)滑不隨滑動而滑動,只能點擊才出現(xiàn)側(cè)滑的話,可以先鎖定
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
這樣就不一直跟著手勢側(cè)滑了
3.一級界面 ListVIew嵌套GridView,GridView得做自設配高度的自定義,不然只能顯示一行,具體參源碼AutoMeasureHeightGridView這個類
4.接下來是解析數(shù)據(jù)綁定數(shù)據(jù)了,還算比較簡單。定義模型類,京東的篩選默認每項顯示數(shù)據(jù)3個即一行。我現(xiàn)在默認的是都是關(guān)閉的,只有第一項是打開的,默認顯現(xiàn)9個即3行,點擊查看更多就能進入下一級頁面。參看圖二
5.二級頁面是一個PopupWindow,設置了PopupWindow的位置和動畫達到,也能像一級界面也樣,右邊側(cè)滑出來,點擊側(cè)滑收回去的效果。
/** * 創(chuàng)建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選中的狀態(tài)對象的存在需要顯示的對象里,設置對象的一個屬性,記錄CheckBox選中的狀態(tài)。
6.對于頁面件數(shù)據(jù)的傳遞使用的接口回調(diào)。包括Adapter數(shù)據(jù)操作的傳出和一級頁面?zhèn)魅攵夗撁?,二級頁面在回傳給一級頁面顯示。一級頁面在傳出給主頁面(這個沒有寫)也可以用其他數(shù)據(jù)傳遞的方式,這只是方法之一。
7.項目下載地址:AndroidScreening_jb51.rar
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android使用Jsoup 抓取頁面的數(shù)據(jù)
本篇文章主要介紹了android使用Jsoup 抓取頁面的數(shù)據(jù),jsoup 是一款Java的HTML解析器,有需要的朋友可以了解一下。2016-11-11android BitmapFactory.Options使用方法詳解
這篇文章主要為大家詳細介紹了android BitmapFactory.Options使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01實例講解Android應用開發(fā)中TabHost的使用要點
這篇文章主要介紹了Android應用開發(fā)中TabHost的使用要點,文中以實例講解了TabHost與Tab的布局方法,需要的朋友可以參考下2016-04-04小心!Listview結(jié)合EditText使用實例中遇到的那些坑
小心!Listview結(jié)合EditText使用實例中遇到的那些坑,解決EditText焦點丟失、保存數(shù)據(jù)以及滾動沖突的問題,感興趣的小伙伴們可以參考一下2016-06-06