Java 动态添加缺少滚动条的视图

Java 动态添加缺少滚动条的视图,java,android,xml,android-layout,dynamic,Java,Android,Xml,Android Layout,Dynamic,我正在动态添加视图,如下所示: LayoutInflater layoutInflater = (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View addView = layoutInflater.inflate(R.layout.dynamicabout,

我正在动态添加视图,如下所示:

            LayoutInflater layoutInflater = 
            (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View addView = layoutInflater.inflate(R.layout.dynamicabout, null);
            TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent);
            textOut.setText(strings.get(index));
            ((ViewGroup) v).addView(addView);
然而,一旦我们到达屏幕的底部和更远处,就没有滚动条了。 我尝试过使用ScrollView,但没有任何效果

dynamicabout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/aboutcontent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="all"/>
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

关于.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/stdpadding"
    android:paddingRight="@dimen/stdpadding"
    android:paddingBottom="@dimen/stdpadding"
    android:paddingTop="@dimen/stdpadding"
    android:orientation="vertical" >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        </ScrollView>
</LinearLayout>

您需要做的是拥有父视图和子视图。将子项添加到父项。父对象在dynamicabout.xml的ScrollView中为LinearLayout。Child是关于XML的。在运行时膨胀XML并将其添加到父视图(ScrollView中的LinearLayout)

p.S.>为父布局设置一个ID,以便能够在其中添加视图,就我所见,它没有ID

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/stdpadding"
    android:paddingRight="@dimen/stdpadding"
    android:paddingBottom="@dimen/stdpadding"
    android:paddingTop="@dimen/stdpadding"
    android:orientation="vertical" >
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 <LinearLayout 
android:id="@+id/linear
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </ScrollView>
</LinearLayout>

请输入以下代码:

我懒惰的一面谢谢你为我写出来:D
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/aboutcontent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="all"/>
        </LinearLayout>


</RelativeLayout>
LinearLayout linear=(LinearLayout)findviewbyId(R.id.linear);
 LayoutInflater layoutInflater = 
            (LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View addView = layoutInflater.inflate(R.layout.dynamicabout, null);
            TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent);
            textOut.setText(strings.get(index));
linearview.addView(addView);