边距不起作用

Rob*_*met 6 android android-layout

我以编程方式进行了以下布局:

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);
Run Code Online (Sandbox Code Playgroud)

但是我没有把它作为setMargins中的值给出,它根本没有任何效果.
是什么原因?

布局具有fill_parent的高度和宽度,因此不会出现问题.

谢谢 :)

小智 0

progressLayout.setGravity(Gravity.CENTER); 
Run Code Online (Sandbox Code Playgroud)

将文本视图和进度条居中对齐。