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 }
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122
做人要厚道,转载请注明出处!