Android编程设置LayoutParams

Android编程设置LayoutParams
 1         RelativeLayout.LayoutParams linearParams = (RelativeLayout.LayoutParams)viewHolder.headerWraper.getLayoutParams();
 2         RelativeLayout.LayoutParams textParams = (RelativeLayout.LayoutParams)viewHolder.textWrapper.getLayoutParams();
 3         
 4         linearParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0); //清空alignParentRight参数
 5         textParams.addRule(RelativeLayout.ALIGN_LEFT, 0);           //清空toLeftOf参数
 6         
 7         if (fromToType == Constants.FromToType.FromToTypeFromThisUser.getValue()) { //根据条件设置Layout参数
 8 
 9             linearParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
10             textParams.addRule(RelativeLayout.LEFT_OF, R.id.header_wrapper);
11             
12             viewHolder.headerWraper.setLayoutParams(linearParams);
13             viewHolder.textWrapper.setLayoutParams(textParams);
14             
15             Logger.d(TAG, "from this user");
16         }
17         else{
18             Logger.d(TAG, "from otehr user");
19             
20             linearParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
21             textParams.addRule(RelativeLayout.RIGHT_OF , R.id.header_wrapper);
22             
23             viewHolder.headerWraper.setLayoutParams(linearParams);
24             viewHolder.textWrapper.setLayoutParams(textParams);
25             
26             viewHolder.textWrapper.setBackgroundResource(R.drawable.chat_other);
27         }
Android编程设置LayoutParams

Android编程设置LayoutParams

上一篇:BeanFactory ApplicationContext


下一篇:Android AppCompat 需要 API 级别 11