How to Right Align elements of a Horizontal LinearLayout
without having to convert it to a RelativeLayout
or wrapping it's elements inside another Layouts.
this is the layout params i'm using inside the layout:
// this is for some elements(ImageButtons)
LinearLayout.LayoutParams lp_ineer_ver = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, Gravity.RIGHT);
lp_ineer_ver.bottomMargin = 2;
lp_ineer_ver.leftMargin = 3;
lp_ineer_ver.topMargin = 2;
// this is for others(TextViews, Buttons)
LinearLayout.LayoutParams elements_params = (LinearLayout.LayoutParams)text1.getLayoutParams();
elements_params.gravity = Gravity.CENTER;
elements_params.leftMargin = 3;
elements_params.weight = 1;
text1.setLayoutParams(elements_params);
Try like this..
LinearLayout.LayoutParams lp_ineer_ver = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
lp_ineer_ver.bottomMargin = 2;
lp_ineer_ver.leftMargin = 3;
lp_ineer_ver.topMargin = 2;
lp_ineer_ver.gravity= Gravity.RIGHT;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.