Android 仿京東側(cè)滑篩選實(shí)例代碼
簡(jiǎn)單介紹
這個(gè)demo寫的是仿京東的側(cè)滑篩選頁面,點(diǎn)擊進(jìn)入篩選后進(jìn)入二級(jí)篩選,兩次側(cè)滑的篩選,還包括ListView+CheckBox滑動(dòng)沖突,ListView+ GridView顯示一行問題解決,接口回調(diào)傳遞數(shù)據(jù)等
效果圖


簡(jiǎn)單得代碼介紹
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.一級(jí)頁面是自定義的layout,作為DrawerLayout的側(cè)滑頁面添加進(jìn)去
menuHeaderView = new RightSideslipLay(ScreeningActivity.this); navigationView.addView(menuHeaderView);
發(fā)現(xiàn)的一個(gè)小的技巧想要側(cè)滑不隨滑動(dòng)而滑動(dòng),只能點(diǎn)擊才出現(xiàn)側(cè)滑的話,可以先鎖定
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);這樣就不一直跟著手勢(shì)側(cè)滑了
3.一級(jí)界面 ListVIew嵌套GridView,GridView得做自設(shè)配高度的自定義,不然只能顯示一行,具體參源碼AutoMeasureHeightGridView這個(gè)類
4.接下來是解析數(shù)據(jù)綁定數(shù)據(jù)了,還算比較簡(jiǎn)單。定義模型類,京東的篩選默認(rèn)每項(xiàng)顯示數(shù)據(jù)3個(gè)即一行。我現(xiàn)在默認(rèn)的是都是關(guān)閉的,只有第一項(xiàng)是打開的,默認(rèn)顯現(xiàn)9個(gè)即3行,點(diǎn)擊查看更多就能進(jìn)入下一級(jí)頁面。參看圖二
5.二級(jí)頁面是一個(gè)PopupWindow,設(shè)置了PopupWindow的位置和動(dòng)畫達(dá)到,也能像一級(jí)界面也樣,右邊側(cè)滑出來,點(diǎn)擊側(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();
}
});
}
此頁面是一個(gè)ListView里包含CheckBox,對(duì)于CheckBox滑動(dòng)選中錯(cuò)位的問題在這個(gè)demo中也有解決,此法一本萬利??梢韵螺ddemo來參考。大體思路是CheckBox選中的狀態(tài)對(duì)象的存在需要顯示的對(duì)象里,設(shè)置對(duì)象的一個(gè)屬性,記錄CheckBox選中的狀態(tài)。
6.對(duì)于頁面件數(shù)據(jù)的傳遞使用的接口回調(diào)。包括Adapter數(shù)據(jù)操作的傳出和一級(jí)頁面?zhèn)魅攵?jí)頁面,二級(jí)頁面在回傳給一級(jí)頁面顯示。一級(jí)頁面在傳出給主頁面(這個(gè)沒有寫)也可以用其他數(shù)據(jù)傳遞的方式,這只是方法之一。
7.項(xiàng)目下載地址:AndroidScreening_jb51.rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android 監(jiān)聽SD卡文件變化的實(shí)現(xiàn)代碼
這篇文章主要介紹了android 監(jiān)聽SD卡文件變化的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-11-11
Android 高仿微信轉(zhuǎn)賬金錢輸入框規(guī)則
這篇文章主要介紹了Android 高仿微信金錢輸入框規(guī)則的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-12-12
activity控制對(duì)話框風(fēng)格、顯示大小與位置
對(duì)于對(duì)話框風(fēng)格大家普遍使用PopupWindow,也有許多朋友開發(fā)設(shè)計(jì)時(shí)使用的是activity對(duì)話框方式,因此,本文對(duì)如何通過activity實(shí)現(xiàn)與PopupWindow相同的效果進(jìn)行詳細(xì)介紹,具有很好的參考價(jià)值,需要的朋友一起來看下吧2016-12-12
Android 中無法取消標(biāo)題欄的問題小結(jié)(兩種方法)
我們都知道取消標(biāo)題欄有兩種方式,一種是在Java代碼中取消,另一種通過設(shè)置styles.xml文件中的Theme即可,下面就兩種方法給大家簡(jiǎn)答介紹下2016-12-12
Android View 測(cè)量流程(Measure)全面解析
這篇文章主要為大家全面解析了Android View 測(cè)量流程Measure,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android 使用Vitamio打造自己的萬能播放器(6)——在線播放(播放列表)
本文主要介紹Android Vitamino在線播放列表,這里給大家提供效果圖和實(shí)例代碼以便大家參考學(xué)習(xí),希望能幫助開發(fā)Android視頻播放的朋友2016-07-07

