【发布时间】:2017-09-14 12:34:01
【问题描述】:
我在 android Studio 中开发和应用程序,现在我遇到了一个奇怪的问题。
我有一个tableRow,其中包含一个TextView 和一个Button。
我正在以编程方式构建它们,我希望tableRow内的button与屏幕右侧对齐。
我已经尝试了很多选项,例如:
button.setGravity(Gravity.RIGHT) 和button.setGravity(Gravity.END) 并尝试在layout_width 中使用fill_parent 为表格提供布局参数,但似乎不起作用。
这是我构建 TableRow 的代码部分:
TableRow new_tablerow = new TableRow(getContext());
layout_pickup_passengers.addView(new_tablerow);
LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
new_tablerow.setLayoutParams(rowParams);
//GLOBAL PASSENGERS
TextView text_pass_type = new TextView(getContext());
new_tablerow.addView(text_pass_type);
text_pass_type.setTextColor(getResources().getColor(R.color.black));
text_pass_type.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
text_pass_type.setText("> Passageiros");
//BUTTON
// Button
final Button button_numberPickerDialog = new Button(getContext());
button_numberPickerDialog.setBackgroundResource(R.color.wallet_bright_foreground_holo_dark);
new_tablerow.addView(button_numberPickerDialog);
button_numberPickerDialog.setGravity(Gravity.RIGHT);
这就是我得到的:
所以您是否只能看到里面的文本向右对齐(0 数字),我希望按钮向右对齐而不是里面的文本。
【问题讨论】:
标签: java android-studio button