片段布局中的ScrollView问题



ScrollView在其中有多个linearLayouts时不会滚动。 ScrollView也位于linearLayout内。以下是我的fragment.xml代码

我在屏幕上方使用youtubePlayer,在此下方使用按钮 在滚动视图中播放其他视频。

我已经进行了搜索和更改,但没有解决。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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="match_parent"
>
<FrameLayout
    android:id="@+id/youtube_frame"
    android:layout_width="0dp"
    android:layout_height="230dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/linearTitle"
        android:orientation="vertical"
        >
        <ScrollView
            android:id="@+id/scrollView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@+id/linearTitle"
            android:layout_marginTop="10dp"
            android:isScrollContainer="false"
            android:fitsSystemWindows="true"
            android:fillViewport="true"
            >

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:weightSum="4.0">

                          <My ImageButtons>

                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:weightSum="4.0">

                   <My ImageButtons>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:weightSum="4.0">

                    <My ImageButtons>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:weightSum="4.0">
                  <My ImageButtons>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:weightSum="4.0">

                   <My ImageButtons>
                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="50dp" />
            </LinearLayout>

        </ScrollView>
        </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

首先,无需将ScrollView放入LinearLayout(因为此LinearLayout除了ScrollView以外没有任何元素(。其次,您应该将ScrollView放在FrameLayout的底部。

请参阅下面:

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/youtube_frame"
        android:layout_width="0dp"
        android:layout_height="230dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:fillViewport="true"
        android:fitsSystemWindows="true"
        android:isScrollContainer="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/youtube_frame">

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4.0">

                <My ImageButtons>

            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4.0">

                <My ImageButtons>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4.0">

                <My ImageButtons>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4.0">
                <My ImageButtons>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4.0">

                <My ImageButtons>
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="50dp" />
        </LinearLayout>

    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

最新更新