Невозможно прокрутить линейный макет с ScrollView - PullRequest
0 голосов
/ 17 октября 2018

Я новичок в 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/>

Ответы [ 3 ]

0 голосов
/ 17 октября 2018

Вам необходимо добавить некоторые атрибуты:

1) В ScrollView:

android:fillViewport="true"

2) И в свой LinearLayout:

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>
0 голосов
/ 17 октября 2018

Используйте ниже код

<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>  
0 голосов
/ 17 октября 2018

Измените 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">
...