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);
}
}
<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>
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();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有