如何右對齊的水平LinearLayout
元素,而無需將其轉換爲RelativeLayout
或包裹它的另一個佈局中的元素。右對齊LinearLayout中的元素?
這是佈局PARAMS我使用裏面的佈置:
// 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);
嘗試設置layout_gravity = 「右」 pogrammatically:像這樣的'PARAMS。重力= Gravity.RIGHT;' –