简体   繁体   English

如何在代码中从一个LinearLayout复制参数并将其设置为另一个LinearLayout?

[英]How to copy params from one LinearLayout and set to another LinearLayout in code?

How to copy params from one LinearLayout and set to another LinearLayout in code ? 如何在代码中从一个LinearLayout复制参数并将其设置为另一个LinearLayout? I have tried like 我尝试过像

LinearLayout.LayoutParams paramsR=(LinearLayout.LayoutParams) llRight.getLayoutParams();
LinearLayout.LayoutParams paramsL=(LinearLayout.LayoutParams) llLeft.getLayoutParams();
paramsR.height=paramsL.height;
paramsR.width=paramsL.width;
llRight.setLayoutParams(paramsR);

but it ignores at all. 但它完全忽略了。 How to solve this problem ? 如何解决这个问题呢 ?

If the parent of llRight & llLeft is RelativeLayout then you should use: 如果llRightllLeft的父llLeftRelativeLayout ,则应使用:

RelativeLayout.LayoutParams paramsR=(RelativeLayout.LayoutParams) llRight.getLayoutParams();
RelativeLayout.LayoutParams paramsL=(RelativeLayout.LayoutParams) llLeft.getLayoutParams();
paramsR.height=paramsL.height;
paramsR.width=paramsL.width;
llRight.setLayoutParams(paramsR);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM