【发布时间】:2015-07-14 15:01:56
【问题描述】:
目前我有一个 按钮列表 显示在 ScrollView 中,但是所有按钮都在左侧并在一列中向下。
我希望这些按钮以 3 列显示,因此当我动态添加行时,一行中有 3 个按钮
这是我必须显示这些按钮的当前代码
// Find the ScrollView
ScrollView scrollView = (ScrollView)
findViewById(R.id.scrollView);
// Create a LinearLayout element
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
// Add Buttons
for (int i = 0; i < 3; i++) {
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
for (int j = 0; j < 20; j++) {
Button button = new Button(this);
button.setText("Some text");
linearLayout.addView(button);
}
}
// Add the LinearLayout element to the ScrollView
scrollView.addView(linearLayout);
}
我尝试为按钮设置布局参数,但没有任何改变
有什么想法吗?
谢谢
【问题讨论】:
-
请查看我发布的答案
标签: android button view scrollview