Android編程實(shí)現(xiàn)仿美團(tuán)或淘寶的多級(jí)分類菜單效果示例【附demo源碼下載】
本文實(shí)例講述了Android編程實(shí)現(xiàn)仿美團(tuán)或淘寶的多級(jí)分類菜單效果。分享給大家供大家參考,具體如下:
這里要實(shí)現(xiàn)的是諸如美團(tuán)/淘寶/百度糯米 多級(jí)分類菜單效果。當(dāng)分類數(shù)量非常多時(shí)可以考慮采用兩級(jí)分類,而諸如美團(tuán)這種表現(xiàn)方式是一個(gè)不錯(cuò)的選擇。
首先上效果圖:

主要代碼:
1. PopupWindow初始化過程:
popupWindow = new PopupWindow(this);
View view = LayoutInflater.from(this).inflate(R.layout.popup_layout, null);
leftLV = (ListView) view.findViewById(R.id.pop_listview_left);
rightLV = (ListView) view.findViewById(R.id.pop_listview_right);
popupWindow.setContentView(view);
popupWindow.setBackgroundDrawable(new PaintDrawable());
popupWindow.setFocusable(true);
popupWindow.setHeight(ScreenUtils.getScreenH(this) * 2 / 3);
popupWindow.setWidth(ScreenUtils.getScreenW(this));
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
darkView.startAnimation(animOut);
darkView.setVisibility(View.GONE);
leftLV.setSelection(0);
rightLV.setSelection(0);
}
});
2.左側(cè)菜單點(diǎn)擊事件:
//左側(cè)ListView點(diǎn)擊事件
leftLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//二級(jí)數(shù)據(jù)
List<SecondClassItem> list2 = firstList.get(position).getSecondList();
//如果沒有二級(jí)類,則直接跳轉(zhuǎn)
if (list2 == null || list2.size() == 0) {
popupWindow.dismiss();
int firstId = firstList.get(position).getId();
String selectedName = firstList.get(position).getName();
handleResult(firstId, -1, selectedName);
return;
}
FirstClassAdapter adapter = (FirstClassAdapter) (parent.getAdapter());
//如果上次點(diǎn)擊的就是這一個(gè)item,則不進(jìn)行任何操作
if (adapter.getSelectedPosition() == position){
return;
}
//根據(jù)左側(cè)一級(jí)分類選中情況,更新背景色
adapter.setSelectedPosition(position);
adapter.notifyDataSetChanged();
//顯示右側(cè)二級(jí)分類
updateSecondListView(list2, secondAdapter);
}
});
3. 右側(cè)菜單點(diǎn)擊事件:
//右側(cè)ListView點(diǎn)擊事件
rightLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//關(guān)閉popupWindow,顯示用戶選擇的分類
popupWindow.dismiss();
int firstPosition = firstAdapter.getSelectedPosition();
int firstId = firstList.get(firstPosition).getId();
int secondId = firstList.get(firstPosition).getSecondList().get(position).getId();
String selectedName = firstList.get(firstPosition).getSecondList().get(position)
.getName();
handleResult(firstId, secondId, selectedName);
}
});
4.頂部標(biāo)簽點(diǎn)擊事件(即顯示/隱藏 分類菜單)
if (popupWindow.isShowing()) {
popupWindow.dismiss();
} else {
popupWindow.showAsDropDown(findViewById(R.id.main_div_line));
popupWindow.setAnimationStyle(-1);
//背景變暗
darkView.startAnimation(animIn);
darkView.setVisibility(View.VISIBLE);
}
5.根據(jù)左側(cè)點(diǎn)擊,刷新右側(cè)ListView
//刷新右側(cè)ListView
private void updateSecondListView(List<SecondClassItem> list2,
SecondClassAdapter secondAdapter) {
secondList.clear();
secondList.addAll(list2);
secondAdapter.notifyDataSetChanged();
}
完整實(shí)例代碼點(diǎn)擊此處本站下載。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android布局layout技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
- Android自定義StepView仿外賣配送進(jìn)度
- Android仿外賣購物車功能
- Android仿百度外賣自定義下拉刷新效果
- Android仿美團(tuán)下拉菜單(商品選購)實(shí)例代碼
- Android仿美團(tuán)分類下拉菜單實(shí)例代碼
- Android仿美團(tuán)淘寶實(shí)現(xiàn)多級(jí)下拉列表菜單功能
- Android模仿美團(tuán)頂部的滑動(dòng)菜單實(shí)例代碼
- 模仿美團(tuán)點(diǎn)評(píng)的Android應(yīng)用中價(jià)格和購買欄懸浮固定的效果
- Android使用RecyclerView仿美團(tuán)分類界面
- Android仿美團(tuán)外賣菜單界面
相關(guān)文章
Android Studio 一鍵生成Json實(shí)體類教程
這篇文章主要介紹了Android Studio 一鍵生成Json實(shí)體類教程,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
Android多國語言轉(zhuǎn)換Excel及Excel轉(zhuǎn)換為string詳解
這篇文章主要給大家介紹了關(guān)于Android多國語言轉(zhuǎn)換Excel以及Excel轉(zhuǎn)換為string的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧2019-01-01
Flutter實(shí)現(xiàn)底部導(dǎo)航欄效果
這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)底部導(dǎo)航欄效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
Android原生TabLayout使用的超全解析(看這篇就夠了)
現(xiàn)在很多app都有頂部可左右切換的導(dǎo)航欄,并且還帶動(dòng)畫效果,要實(shí)現(xiàn)這種導(dǎo)航欄,可以使用Android原生的Tablayout也可以借助第三方框架實(shí)現(xiàn),這篇文章主要給大家介紹了關(guān)于Android原生TabLayout使用的相關(guān)資料,需要的朋友可以參考下2022-09-09
Android實(shí)現(xiàn)九宮格解鎖的實(shí)例代碼
本篇文章主要介紹了Android九宮格解鎖的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
Android實(shí)現(xiàn)百度地圖兩點(diǎn)畫弧線
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)百度地圖兩點(diǎn)畫弧線,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01

