以编程方式在scrollView上设置边距

时间:2011-06-10 08:05:10

标签: android android-layout

您好我正在尝试使用此代码在ScrollView上设置边距,但没有任何反应。

    ScrollView sv = new ScrollView(this);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);


    LayoutParams layoutParams = new ScrollView.LayoutParams(
            ScrollView.LayoutParams.FILL_PARENT,
            ScrollView.LayoutParams.WRAP_CONTENT);
    // layoutParams.bottomMargin = 100;

    layoutParams.setMargins(0, 0, 0, 100);

    sv.setLayoutParams(layoutParams);

    sv.addView(ll);

    // Add a TableView to ScrollView...

    // Display my view
    this.setContentView(sv);

我要做的是在ScrollView旁边放一些按钮,这样你就可以看到它们。

我对Android开发很陌生,所以任何建议都值得赞赏。

/奥莱

1 个答案:

答案 0 :(得分:1)

我认为layoutParams.setMargins(0,0,0,100);确实有效。但你不要以这种方式在底部添加按钮。看看以下链接

http://www.anddev.org/code-snippets-for-android-f33/relativelayout-scrollview-buttons-at-bottom-t8904.html

Two equal sized buttons at bottom of scrollview

相关问题