android仿京東商品屬性篩選功能
篩選和屬性選擇是目前非常常用的功能模塊;幾乎所有的APP中都會使用;
點(diǎn)擊篩選按鈕會彈出一個(gè)自己封裝好的popupWindow,實(shí)用方法非常簡單;兩行代碼直接顯示;(當(dāng)然初始化數(shù)據(jù)除外)
這里和以前用到的流式布局有些不一樣:流式布局
以前使用的是單個(gè)分類,而且也沒有在項(xiàng)目中大量實(shí)用;這個(gè)篩選功能除了數(shù)據(jù)外幾乎都是從項(xiàng)目中Copy出來的;
整個(gè)popupWindow布局就是一個(gè)自定義的ListView,這個(gè)自定義的listview主要是控制listview的高度;
如果數(shù)據(jù)少的話就是自適應(yīng),如果數(shù)據(jù)多了就限制高度為屏幕的一半;
自定義的ListView:
public class CustomHeightListView extends ListView { private Context mContext; public CustomHeightListView(Context context) { this(context, null); } public CustomHeightListView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public CustomHeightListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { mContext = context; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { try { //最大高度顯示為屏幕內(nèi)容高度的一半 Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay(); DisplayMetrics d = new DisplayMetrics(); display.getMetrics(d); //設(shè)置控件高度不能超過屏幕高度一半(d.heightPixels / 2,下面有清空按鈕所以再減200,也可隨意換成自己想要的高度) heightMeasureSpec = MeasureSpec.makeMeasureSpec(d.heightPixels / 2 - 200, MeasureSpec.AT_MOST); } catch (Exception e) { e.printStackTrace(); } //重新計(jì)算控件高、寬 super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
ListView中每個(gè)item是一個(gè)流式布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/tv_type_name" android:layout_width="match_parent" android:layout_height="wrap_content" /> <com.example.zheng.flowlayoutdemo.view.SkuFlowLayout android:id="@+id/layout_property" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
整個(gè)popupwindow都封裝在一個(gè)類中,創(chuàng)建的時(shí)候只需把數(shù)據(jù)源傳遞過去即可,實(shí)用的時(shí)候直接show就可以了
flowPopWindow = new FlowPopWindow(MainActivity.this, dictList); flowPopWindow.showAsDropDown(ivBack);
當(dāng)點(diǎn)擊確定的時(shí)候直接設(shè)置一個(gè)監(jiān)聽即可:
flowPopWindow.setOnConfirmClickListener(new FlowPopWindow.OnConfirmClickListener() { @Override public void onConfirmClick() { StringBuilder sb = new StringBuilder(); for (FiltrateBean fb : dictList) { List<FiltrateBean.Children> cdList = fb.getChildren(); for (int x = 0; x < cdList.size(); x++) { FiltrateBean.Children children = cdList.get(x); if (children.isSelected()) sb.append(fb.getTypeName() + ":" + children.getValue() + ";"); } } if (!TextUtils.isEmpty(sb.toString())) Toast.makeText(MainActivity.this, sb.toString(), Toast.LENGTH_LONG).show(); } }
點(diǎn)擊打開鏈接免費(fèi)下載源碼
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
超簡單Android集成華為HMS Scankit 掃碼SDK實(shí)現(xiàn)掃一掃二維碼
這篇文章主要介紹了超簡單Android集成華為HMS Scankit 掃碼SDK實(shí)現(xiàn)掃一掃二維碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03Android實(shí)現(xiàn)Reveal圓形Activity轉(zhuǎn)場動畫的完整步驟
這篇文章主要給大家介紹了關(guān)于Android Reveal圓形Activity轉(zhuǎn)場動畫的實(shí)現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11Android自定義button點(diǎn)擊效果的兩種方式
這篇文章主要為大家詳細(xì)介紹了Android自定義button點(diǎn)擊效果的兩種方式,感興趣的小伙伴們可以參考一下2016-05-05Hook實(shí)現(xiàn)Android 微信、陌陌 、探探位置模擬(附源碼下載)
這篇文章主要介紹了Hook實(shí)現(xiàn)Android 微信、陌陌 、探探位置模擬(附源碼下載)的相關(guān)資料,需要的朋友可以參考下2017-03-03Android動效Compose貝塞爾曲線動畫規(guī)格詳解
這篇文章主要為大家介紹了Android動效Compose貝塞爾曲線動畫規(guī)格詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11關(guān)于Android Activity之間跳轉(zhuǎn)問題(Intent)
這篇文章主要介紹了Android Activity之間跳轉(zhuǎn)Intent,當(dāng)一個(gè)Acitivity需要啟動另一個(gè)Activity時(shí),通過Intent來表達(dá)自己的意圖,告知系統(tǒng)啟動哪個(gè)Activity,本文給大家詳細(xì)講解,需要的朋友可以參考下2022-10-10