Skip to content Skip to sidebar Skip to footer

Set Scrollview + Fixed Button Programatically On Android With Settext.

I' m at this point stuck : I want to have a scrollview + a fixed button at the bottom, but Programatically Way ! I can' t go with XML for some technical reason. Actually i have t

Solution 1:

try this

LinearLayoutlayout=newLinearLayout(this);
LinearLayout.LayoutParamslp=newLinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(lp);

ScrollViewscroll=newScrollView(this);
LinearLayout.LayoutParamsslp=newLinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT,0, 1.0f);
scroll.setLayoutParams(slp);

Buttonbtn=newButton(this);
ViewGroup.LayoutParamsblp=newViewGroup.LayoutParams(
        LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(blp);
btn.setText("Click Me");

layout.addView(scroll);
layout.addView(btn);

setContentView(layout);

Solution 2:

If you are trying to create a view where the upper portion of the screen is a scrolling list, and the bottom portion is a button, put the scrollview inside a linearlayout, and put the button in the linearlayout below the scrollview.

http://developer.android.com/reference/android/widget/LinearLayout.html

Post a Comment for "Set Scrollview + Fixed Button Programatically On Android With Settext."