简体   繁体   中英

How to fix my LinearLayout to scroll down when content exceeds view

I am adding views to my adapter dynamically and when the views exceeds the screen boundaries I am unable to see the full views.

I have tried android:isScrollContainer="true" and android:scrollbars="vertical" without any luck.

public void onAddField(View v) {
        final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View rowView = inflater.inflate(R.layout.field, null);
        spin = rowView.findViewById(R.id.type_spinner2);
        weightLayout = rowView.findViewById(R.id.myLayout);
        getdata();
        spin.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, arrayList2));
        parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#E5E5E5"
        android:orientation="vertical"
        android:scrollbars="vertical"
        android:isScrollContainer="true">

Try to use this:

 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="50dp"
                android:text="TextView" />
        </LinearLayout>

    </ScrollView>

</LinearLayout>

This way your ScrollView will expand with your LinerLayout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM