ScrollView не прокручивает все элементы, присутствующие в android - PullRequest
0 голосов
/ 17 апреля 2020

У меня есть список из 31 элемента, каждый из которых имеет 4 textViews. Я оборачиваю все текстовые представления в линейный макет. Я показал 1 в коде. Так же, как и этот, у меня есть еще 30:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="loren"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="10"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="5"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="2"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="25"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="2"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="9"
            android:textColor="#000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="2"/>
    </LinearLayout>

и результирующий код, для ясности которого показан только один.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fragment_globe"
    android:background="@color/dashBackground">

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

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:orientation="horizontal">
                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="loren"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="10"/>

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="5"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="2"/>

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="25"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="2"/>

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:text="9"
                        android:textColor="#000"
                        android:gravity="center"
                        android:textSize="20dp"
                        android:layout_weight="2"/>
                </LinearLayout>

            </LinearLayout>


    </ScrollView>


</androidx.constraintlayout.widget.ConstraintLayout>

Я не могу прокрутить все элементы или все линейные макеты. Я могу прокрутить до некоторой точки, но затем она перестает прокручиваться вниз. Я новичок в android, пожалуйста, помогите мне.

Ответы [ 3 ]

1 голос
/ 17 апреля 2020

Пожалуйста, добавьте android:fillViewport="true" и android:scrollbars="vertical" в тег ScrollView ...

1 голос
/ 17 апреля 2020

Используйте это:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"   //set this to wrap
        android:fillViewport="true"   //set fillviewport to true.
        android:orientation="vertical">  

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"  //set this to match parent.
                android:orientation="vertical">

Вам необходимо установить высоту представления прокрутки для переноса и LinearLayout, который является дочерним элементом высоты ScrollView, равным match_parent. Также установите для области просмотра значение true.

1 голос
/ 17 апреля 2020

Добавьте эти два атрибута в ScrollView:

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...