如何修复我的LinearLayout以在内容超出视图时向下滚动

问题描述 投票:-1回答:1

我正在动态地向我的适配器添加视图,当视图超出屏幕边界时,我无法看到完整视图。

我没有运气就试过android:isScrollContainer="true"android:scrollbars="vertical"

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">
java android scroll layout-inflater
1个回答
0
投票

试着用这个:

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

这样您的ScrollView将随您的LinearLayout一起扩展。

© www.soinside.com 2019 - 2024. All rights reserved.