首页 > android > android安卓获取控件高度,设置控件高度,包括透明度

android安卓获取控件高度,设置控件高度,包括透明度

2015年11月24日 发表评论 阅读评论

View today_finish_view = View.inflate(context, R.layout.tab_today_viewpager_today_finish, null);

RelativeLayout center_alpha_relative = (RelativeLayout) today_finish_view.findViewById(R.id.center_alpha_relative);
//获取高度
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
center_alpha_relative.measure(w, h);
int height = center_alpha_relative.getMeasuredHeight();

//设置高度
LinearLayout center_alpha_bg_linear = (LinearLayout) today_finish_view.findViewById(R.id.center_alpha_bg_linear);
//明明是LinearLayout,为什么用RelativeLayout.LayoutParams(网上说因为整个view是View.inflate进去的)
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) center_alpha_bg_linear.getLayoutParams();
params.height = height;
center_alpha_bg_linear.setLayoutParams(params);

 

//设置透明度
center_alpha_bg_linear.getBackground().setAlpha(200);

  1. 本文目前尚无任何评论.
您必须在 登录 后才能发布评论.
css.php