Android 无法使用ScrollView滚动线性布局

Android 无法使用ScrollView滚动线性布局,android,scrollview,android-linearlayout,Android,Scrollview,Android Linearlayout,我是Android新手。我正在创建一个表单来添加用户。由于表单字段很多,我需要向下滚动。我读到ScrollView只接受一个子视图。我将视图包装在一个线性布局中,它是ScrollView的直接子视图 <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:backgr

我是Android新手。我正在创建一个表单来添加用户。由于表单字段很多,我需要向下滚动。我读到ScrollView只接受一个子视图。我将视图包装在一个线性布局中,它是ScrollView的直接子视图

<ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorWhite"
                android:animateLayoutChanges="true"
                android:scrollbars="none">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

                <EditText... />

                <EditText.../>

                <EditText... />

                <EditText.../>

                <LinearLayout... >

                <LinearLayout... >

                <LinearLayout... >

                <TextView... />
     </LinearLayout>
 <ScrollView/>

将滚动视图的xml更改为

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

将滚动视图的xml更改为

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

您需要添加一些属性:

1) 到您的滚动视图:

android:fillViewport="true"
2) 对于您的直线布局:

android:descendantFocusability="blocksDescendants"
例如:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cardDetailScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:id="@+id/card_detail_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:descendantFocusability="blocksDescendants">

        Your Content...

    </LinearLayout>
</ScrollView>

你的内容。。。

您需要添加一些属性:

1) 到您的滚动视图:

android:fillViewport="true"
2) 对于您的直线布局:

android:descendantFocusability="blocksDescendants"
例如:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cardDetailScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:id="@+id/card_detail_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:descendantFocusability="blocksDescendants">

        Your Content...

    </LinearLayout>
</ScrollView>

你的内容。。。
使用下面的代码

<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android"  
     xmlns:tools="http://schemas.android.com/tools" 
     android:fillViewport="true"    
    android:layout_marginTop="30dp"  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content"  
    android:id="@+id/scrollView">  


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

        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 1" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 2" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 3" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 4" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 5" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 6" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 7" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 8" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 9" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 10" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 11" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 12" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 13" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 14" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 15" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 16" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 17" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 18" />  

        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 19" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 20" />  

    </LinearLayout>  

</ScrollView>  

使用下面的代码

<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android"  
     xmlns:tools="http://schemas.android.com/tools" 
     android:fillViewport="true"    
    android:layout_marginTop="30dp"  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content"  
    android:id="@+id/scrollView">  


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

        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 1" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 2" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 3" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 4" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 5" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 6" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 7" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 8" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 9" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 10" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 11" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 12" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 13" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 14" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 15" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 16" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 17" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 18" />  

        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 19" />  
        <Button  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:text="Button 20" />  

    </LinearLayout>  

</ScrollView>  


您的问题是否解决?您的问题是否解决?