googlesmaple 地址:
https://github.com/google/flexbox-layout
参照web flex实现的布局方式。值得学习一下。前段时间的标签云确实有点小问题,flex很好的解决了它.
// 通过代码向FlexboxLayout添加View
TextView textView = new TextView(this);
textView.setText("TestLabel");
textView.setGravity(Gravity.CENTER);
textView.setBackgroundResource(R.drawable.label_bg_shape);
textView.setPadding(DensityUtil.dip2px(mContext,15),0,DensityUtil.dip2px(mContext,15),0);
textView.setTextColor(getResources().getColor(R.color.text_color));
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,DensityUtil.dip2px(mContext,40)));
flexboxLayout.addView(textView);
//通过FlexboxLayout.LayoutParams 设置子元素支持的属性
// ViewGroup.LayoutParams params = textView.getLayoutParams();
// if(params instanceof FlexboxLayout.LayoutParams){
// FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) params;
// layoutParams.setFlexBasisPercent(0.5f);
// }
网友评论