Recyclerview添加headerView,如果header不能充满父布局的宽度,需要单独设置LayoutParams
View header = getLayoutInflater().inflate(R.layout.header, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
header.setLayoutParams(params);
mRecyclerview.addHeaderView(header);
流式布局中根据标签是否超过1行控制展开收起按钮显示,flowLayout(自定义的).getLinesCount();获取行数之前需要measure处理,因为行数需要通过onMeasure方法内部进行计算处理
flowLayout.measure(View.MeasureSpec.AT_MOST,View.MeasureSpec.EXACTLY);
//是否显示展开按钮
int linesCount = flowLayout.getLinesCount();
if (linesCount<=1) {
mFold.setVisibility(View.GONE);
} else {
mFold.setVisibility(View.VISIBLE);
}
动态的改变相对布局中控件的位置等属性
这个有点麻烦,跟想象的不太一样,有的时候管事,有时候不管事,调了半天终于基本达到效果了
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.topMargin = 240;
mTextView.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 = 200;
params1.bottomMargin = 200;
mLinearLayout.setLayoutParams(params1);
mTextView.setTextSize(COMPLEX_UNIT_PX,34);
mRatingBar.setStarSize(86);
mRatingBar.setStarsSeparation(42);