I’m writing an Android application that has a scrollview which contains a linearlayout:
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity=top"
android:layout_marginTop="240dip"
android:layout_marginRight="0dip"
android:layout_marginBottom="60dip">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/centerlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:layout_marginRight="20dip"
android:layout_marginLeft="10dip"
android:layout_marginBottom="120dip">
As you see, scrollview’s margin top is “240dip” . I want to be able to change it in my Java code. I tried this:
ScrollView scrollView=(ScrollView)findViewById(R.id.ScrollView01);
LayoutParams params=scrollView.getLayoutParams();
But I can’t do this: params.top=100; Would you please help me how I can do it?
What do you mean that you “can’t do this”. You would have to do
params.top=100;and thenscrollView.setLayoutParams(params);.But you could change it to: