首页 > 学院 > 开发设计 > 正文

动态的改变相对布局中控件的位置等属性

2019-11-09 18:17:50
字体:
来源:转载
供稿:网友

Recyclerview添加headerView,如果header不能充满父布局的宽度,需要单独设置LayoutParams

View header = getLayoutInflater().inflate(R.layout.header_evaluate_info, null);LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);header.setLayoutParams(params);mRvfEvaluate.addHeaderView(header);

流式布局中根据标签是否超过1行控制展开收起按钮显示,mFlLable.getLinesCount();获取行数之前需要measure处理,因为行数需要通过onMeasure方法内部进行计算处理

mFlLable.measure(View.MeasureSpec.AT_MOST,View.MeasureSpec.EXACTLY);//是否显示展开按钮int linesCount = mFlLable.getLinesCount();if (linesCount<=1) { mLlFold.setVisibility(View.GONE);} else { mLlFold.setVisibility(View.VISIBLE);}

动态的改变相对布局中控件的位置等属性

这个有点麻烦,跟想象的不太一样,有的时候管事,有时候不管事,调了半天终于基本达到效果了

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);params.addRule(RelativeLayout.CENTER_HORIZONTAL);params.topMargin = AutoUtils.getPercentHeightSize(240);mTvTips.setLayoutParams(params);RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);params1.addRule(RelativeLayout.ALIGN_PARENT_END);params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);params1.rightMargin = AutoUtils.getPercentHeightSize(200);params1.bottomMargin = AutoUtils.getPercentHeightSize(200);mLlAnonymity.setLayoutParams(params1); mTvTips.setTextSize(COMPLEX_UNIT_PX,AutoUtils.getPercentWidthSize(34)); mSrbScore.setStarSize(AutoUtils.getPercentWidthSize(86)); mSrbScore.setStarsseparation(AutoUtils.getPercentWidthSize(42));
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表