안 드 로 이 드 모방 경 동 상품 속성 선별 기능
필터 단 추 를 누 르 면 봉 인 된 popupWindow 가 팝 업 됩 니 다.실 용적 인 방법 은 매우 간단 합 니 다.두 줄 코드 를 직접 표시 합 니 다.(물론 데이터 초기 화 제외)
여 기 는 예전 에 사 용 했 던 흐름 식 구조 와 약간 다르다.
이전에 사용 한 것 은 하나의 분류 이 고 프로젝트 에서 대량으로 실 용적 이지 않 았 다.이 선별 기능 은 데 이 터 를 제외 하고 거의 항목 에서 복사 되 었 다.
전체 popupWindow 레이아웃 은 사용자 정의 ListView 입 니 다.이 사용자 정의 listview 는 주로 listview 의 높이 를 제어 합 니 다.
데이터 가 적 으 면 자가 적응 이 고 데이터 가 많 으 면 화면의 절반 으로 높이 를 제한 합 니 다.
사용자 정의 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 {
//
Display display = ((Activity) mContext).getWindowManager().getDefaultDisplay();
DisplayMetrics d = new DisplayMetrics();
display.getMetrics(d);
// (d.heightPixels / 2, 200, )
heightMeasureSpec = MeasureSpec.makeMeasureSpec(d.heightPixels / 2 - 200, MeasureSpec.AT_MOST);
} catch (Exception e) {
e.printStackTrace();
}
// 、
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
ListView 의 모든 아 이 템 은 스 트림 레이아웃 입 니 다.
<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>
전체 popupwindow 는 하나의 클래스 에 패키지 되 어 있 습 니 다.만 들 때 데이터 원본 을 전달 하면 됩 니 다.실 용적 일 때 직접 show 하면 됩 니 다.
flowPopWindow = new FlowPopWindow(MainActivity.this, dictList);
flowPopWindow.showAsDropDown(ivBack);
확인 을 클릭 할 때 감청 을 직접 설정 하면 됩 니 다.
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();
}
}
클릭 하여 링크 열기 무료흐름 식 레이아웃이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.