Olle
Olle

Reputation: 315

Set the margins on a scrollView programmatically

Hi i´m trying to set the margins on a ScrollView with this code but nothing happens.

    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);

What I'm trying to do is have some buttons bellow the ScrollView so you always see them.

I'm quite new to Android development so any suggestions are appreciated.

/Olle

Upvotes: 2

Views: 5575

Answers (1)

con_9
con_9

Reputation: 2511

I think layoutParams.setMargins(0, 0, 0, 100); does works.but you dont add buttons at the bottom in this way. check out the following links

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

Two equal sized buttons at bottom of scrollview

Upvotes: 1

Related Questions