Mehmet Zaim
Mehmet Zaim

Reputation: 95

How to add scrollbar or scrollview in android with class java not xml?

How to add scrollbar or scrollview in android with class java not xml this code?

LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
view = inflater.inflate(R.layout.srvr, null);
layout = (RelativeLayout) view.findViewById(R.id.relativeLayout1);
RelativeLayout.LayoutParams labelLayoutParams = new  RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

layout.setLayoutParams(labelLayoutParams);

labelLayoutParams = new RelativeLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    labelLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    labelLayoutParams.leftMargin=120;

   final EditText tt = new EditText(this);
      tt.setTag(i);
      tt.setText(DisplayName_list[i].toString());
      tt.setMinWidth(230);
      tt.setMaxWidth(230);
      tt.setMaxLines(1);

Upvotes: 0

Views: 2132

Answers (3)

Gajendra kumar
Gajendra kumar

Reputation: 35

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView"
    android:layout_below="@+id/activity_main_webview"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="40dp" />

Upvotes: 0

Gum Naam
Gum Naam

Reputation: 1

include this as parent

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

// Here should b your Layout tag

</ScrollView>

Upvotes: 0

Marcin S.
Marcin S.

Reputation: 11191

As I understood well you want to create a ScrollView programatically. You create it as any other views:

ScrollView sc = new ScrollView(this);
sc.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
sc.setFillViewport(true);

And then you have to add to it your view. Make sure that your view you are adding to the ScrollView is a root view.

sc.addView(ROOT_VIEW)

In your case ROOT_VIEW is a layout which is RelativeLayout

Upvotes: 1

Related Questions