我希望我的两个号码选手并排。我无法将它们并排放在一起。我有一个设置为重心(feetPicker)然后如果我向左或向右设置另一个(inchesPicker),它会进入对话框的角落,而不是恰好在彼此旁边。
任何人都可以告诉我如何使用以下代码实现与framelayout并排看起来很好的数字选择器吗?我是Android(java)的新手,所以任何帮助将不胜感激:)
谢谢!
@Override
protected View onCreateDialogView() {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams2.gravity = Gravity.RIGHT;
feetPicker = new NumberPicker(getContext());
feetPicker.setLayoutParams(layoutParams);
inchesPicker = new NumberPicker(getContext());
inchesPicker.setLayoutParams(layoutParams2);
FrameLayout dialogView = new FrameLayout(getContext());
dialogView.addView(feetPicker);
dialogView.addView(inchesPicker);
return dialogView;
}
答案 0 :(得分:0)
您是否尝试将每个号码选择器的布局重力设置为LEFT
和RIGHT
?像这样:
layoutParams.gravity = Gravity.CENTER | Gravity.LEFT; // center left
layoutParams2.gravity = Gravity.CENTER | Gravity.RIGHT; // center right