片段布局中的滚动视图问题

时间:2019-06-25 11:54:15

标签: java android

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>

1 个答案:

答案 0 :(得分:0)

首先,无需将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>