【发布时间】:2012-09-05 09:55:30
【问题描述】:
我以编程方式制作了以下布局:
LinearLayout progressLayout = new LinearLayout(this);
progressLayout.setOrientation(LinearLayout.VERTICAL);
TextView t = new TextView(this);
t.setText("Test..");
t.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
LayoutParams l = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
l.setMargins(10, 10, 10, 25); ===> does not work?
t.setLayoutParams(l);
ProgressBar circle = new ProgressBar(this, null,
android.R.attr.progressBarStyleLarge);
circle.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
progressLayout.setLayoutParams(new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.FILL_PARENT));
progressLayout.setGravity(Gravity.CENTER);
progressLayout.addView(t);
progressLayout.addView(circle);
this.setContentView(progressLayout);
但是我在 setMargins 中给出的值没有任何意义,它根本没有任何效果。
是什么原因?
布局的高度和宽度为fill_parent,所以这不是问题..
谢谢:)
【问题讨论】:
-
你使用什么样的 LayoutParams ?
-
您应该使用 LinearLayout.LayoutParams,因为您将视图放在 LinearLayout 中(尽管这应该不是问题,因为两者都是 MarginLayoutParams)