android仿京東商品屬性篩選功能
篩選和屬性選擇是目前非常常用的功能模塊;幾乎所有的APP中都會(huì)使用;

點(diǎn)擊篩選按鈕會(huì)彈出一個(gè)自己封裝好的popupWindow,實(shí)用方法非常簡(jiǎn)單;兩行代碼直接顯示;(當(dāng)然初始化數(shù)據(jù)除外)
這里和以前用到的流式布局有些不一樣:流式布局
以前使用的是單個(gè)分類(lèi),而且也沒(méi)有在項(xiàng)目中大量實(shí)用;這個(gè)篩選功能除了數(shù)據(jù)外幾乎都是從項(xiàng)目中Copy出來(lái)的;
整個(gè)popupWindow布局就是一個(gè)自定義的ListView,這個(gè)自定義的listview主要是控制listview的高度;
如果數(shù)據(jù)少的話(huà)就是自適應(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è)置控件高度不能超過(guò)屏幕高度一半(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è)類(lèi)中,創(chuàng)建的時(shí)候只需把數(shù)據(jù)源傳遞過(guò)去即可,實(shí)用的時(shí)候直接show就可以了
flowPopWindow = new FlowPopWindow(MainActivity.this, dictList);
flowPopWindow.showAsDropDown(ivBack);
當(dāng)點(diǎn)擊確定的時(shí)候直接設(shè)置一個(gè)監(jiān)聽(tīng)即可:
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)擊打開(kāi)鏈接免費(fèi)下載源碼
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Flutter Http網(wǎng)絡(luò)請(qǐng)求實(shí)現(xiàn)詳解
這篇文章主要介紹了Flutter Http網(wǎng)絡(luò)請(qǐng)求實(shí)現(xiàn)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
Android 高仿微信語(yǔ)音聊天頁(yè)面高斯模糊(毛玻璃效果)
大家在使用微信聊天的時(shí)候有沒(méi)有注意到微信語(yǔ)言聊天用的是高斯模糊效果,基于代碼是如何實(shí)現(xiàn)的呢?下面小編給大家?guī)?lái)了Android 高仿微信語(yǔ)音聊天頁(yè)面高斯模糊(毛玻璃效果),感興趣的朋友一起看下吧2016-08-08
Flutter Flar動(dòng)畫(huà)使用實(shí)戰(zhàn)示例
這篇文章主要為大家介紹了Flutter Flar動(dòng)畫(huà)使用實(shí)戰(zhàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
Android實(shí)現(xiàn)圖片區(qū)域裁剪功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片區(qū)域裁剪功能,調(diào)用相冊(cè)、拍照實(shí)現(xiàn)縮放、切割圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android權(quán)限詢(xún)問(wèn)的實(shí)例詳解
這篇文章主要介紹了Android權(quán)限詢(xún)問(wèn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09
android 加載本地聯(lián)系人實(shí)現(xiàn)方法
在android開(kāi)發(fā)過(guò)程中,有些功能需要訪(fǎng)問(wèn)本地聯(lián)系人列表,本人搜集整理了一番,拿出來(lái)和大家分享一下,希望可以幫助你們2012-12-12
Android安卓中循環(huán)錄像并檢測(cè)內(nèi)存卡容量
這篇文章主要介紹了Android安卓中循環(huán)錄像并檢測(cè)內(nèi)存卡容量,當(dāng)內(nèi)存卡空間已滿(mǎn)時(shí),本文還實(shí)現(xiàn)自動(dòng)刪除視頻列表里面的第一個(gè)文件,需要的朋友可以參考下2015-06-06
Android App打包加固后的APK無(wú)法安裝問(wèn)題解決
Android應(yīng)用當(dāng)中,很多隱私信息都是以 字符串的形式存在的,所以需要加密,本文主要介紹了Android App打包加固后的APK無(wú)法安裝問(wèn)題解決,感興趣的可以了解一下2024-01-01

