簡體   English   中英

滾動視圖內的約束布局不滾動

[英]constraintlayout inside scrollview not scroll

在我的項目中,當我在滾動視圖中放置約束布局時,不滾動並且約束布局是固定的。 這是我的 xml 布局:

    <?xml version="1.0" encoding="utf-8"?>
<layout 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"
    xmlns:williamchart="http://schemas.android.com/apk/res-auto">

    <data>

    </data>

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/mdrawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:foregroundGravity="right"
        android:layoutDirection="rtl">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/back">


            <androidx.appcompat.widget.Toolbar
                android:id="@+id/app_bar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:alpha="0.77"
                android:background="#12315C"
                android:gravity="right"
                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"

                    android:gravity="right"
                    android:orientation="vertical"
                    tools:layout_editor_absoluteX="16dp"
                    tools:layout_editor_absoluteY="14dp">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">


                        <ImageView
                            android:id="@+id/hammenu"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentStart="true"
                            android:layout_alignParentTop="true"
                            android:paddingTop="6dp"
                            android:src="@drawable/hammenu" />

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_alignParentTop="true"
                            android:layout_marginTop="0dp"
                            android:foregroundGravity="center_vertical|center|center_horizontal"
                            android:gravity="center|center_horizontal|center_vertical"
                            android:text="بازارها"
                            android:textColor="@android:color/background_light"
                            android:textSize="18dp"
                            android:textStyle="bold" />
                    </RelativeLayout>
                </LinearLayout>
            </androidx.appcompat.widget.Toolbar>

            <ScrollView
                android:id="@+id/scroll"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="8dp"

                android:fillViewport="true"
                android:isScrollContainer="true"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/app_bar"
                williamchart:layout_constraintEnd_toEndOf="parent"
                williamchart:layout_constraintStart_toStartOf="parent">


                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:animateLayoutChanges="true"
                    android:isScrollContainer="true"
                    android:nestedScrollingEnabled="true"
                    android:orientation="vertical">


                    <com.google.android.material.card.MaterialCardView
                        android:id="@+id/materialcardview8"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        app:layout_constraintStart_toStartOf="parent"
                        williamchart:cardBackgroundColor="@android:color/transparent"
                        williamchart:cardCornerRadius="32dp"
                        williamchart:layout_constraintHeight_percent="0.25"
                        williamchart:layout_constraintTop_toBottomOf="@+id/materialcardview6"
                        williamchart:layout_constraintWidth_percent="0.4">

                        <io.alterac.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/blurLayout7"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            blurkit:blk_downscaleFactor="0.30"
                            blurkit:blk_fps="0" />


                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:id="@+id/imageView7"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="8dp"
                                android:elevation="4dp"
                                williamchart:layout_constraintBottom_toBottomOf="parent"
                                williamchart:layout_constraintDimensionRatio="h,15:9"
                                williamchart:layout_constraintEnd_toEndOf="parent"
                                williamchart:layout_constraintStart_toStartOf="parent"
                                williamchart:layout_constraintTop_toTopOf="parent"
                                williamchart:srcCompat="@drawable/mypardis" />
                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>

                    <com.google.android.material.card.MaterialCardView
                        android:id="@+id/materialcardview6"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        app:layout_constraintStart_toStartOf="parent"
                        williamchart:cardBackgroundColor="@android:color/transparent"
                        williamchart:cardCornerRadius="32dp"
                        williamchart:layout_constraintHeight_percent="0.25"
                        williamchart:layout_constraintTop_toBottomOf="@+id/materialcardview4"
                        williamchart:layout_constraintWidth_percent="0.4">

                        <io.alterac.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/blurLayout5"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            blurkit:blk_downscaleFactor="0.30"
                            blurkit:blk_fps="0" />


                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:id="@+id/imageView5"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="8dp"
                                android:elevation="4dp"
                                williamchart:layout_constraintBottom_toBottomOf="parent"
                                williamchart:layout_constraintDimensionRatio="h,15:9"
                                williamchart:layout_constraintEnd_toEndOf="parent"
                                williamchart:layout_constraintStart_toStartOf="parent"
                                williamchart:layout_constraintTop_toTopOf="parent"
                                williamchart:srcCompat="@drawable/mypardis" />
                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>


                    <com.google.android.material.card.MaterialCardView
                        android:id="@+id/materialcardview4"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        app:layout_constraintStart_toStartOf="parent"
                        williamchart:cardBackgroundColor="@android:color/transparent"
                        williamchart:cardCornerRadius="32dp"
                        williamchart:layout_constraintHeight_percent="0.25"
                        williamchart:layout_constraintTop_toBottomOf="@+id/materialcardview2"
                        williamchart:layout_constraintWidth_percent="0.4">

                        <io.alterac.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/blurLayout3"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            blurkit:blk_downscaleFactor="0.30"
                            blurkit:blk_fps="0" />


                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:id="@+id/imageView3"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="8dp"
                                android:elevation="4dp"
                                williamchart:layout_constraintBottom_toBottomOf="parent"
                                williamchart:layout_constraintDimensionRatio="h,15:9"
                                williamchart:layout_constraintEnd_toEndOf="parent"
                                williamchart:layout_constraintStart_toStartOf="parent"
                                williamchart:layout_constraintTop_toTopOf="parent"
                                williamchart:srcCompat="@drawable/mypardis" />
                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>

                    <com.google.android.material.card.MaterialCardView
                        android:id="@+id/materialcardview2"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        app:layout_constraintStart_toStartOf="parent"
                        williamchart:cardBackgroundColor="@android:color/transparent"
                        williamchart:cardCornerRadius="32dp"
                        williamchart:layout_constraintHeight_percent="0.25"
                        williamchart:layout_constraintTop_toTopOf="parent"
                        williamchart:layout_constraintWidth_percent="0.4">

                        <io.alterac.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/blurLayout1"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            blurkit:blk_downscaleFactor="0.30"
                            blurkit:blk_fps="0" />


                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:id="@+id/imageView1"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="8dp"
                                android:elevation="4dp"
                                williamchart:layout_constraintBottom_toBottomOf="parent"
                                williamchart:layout_constraintDimensionRatio="h,15:9"
                                williamchart:layout_constraintEnd_toEndOf="parent"
                                williamchart:layout_constraintStart_toStartOf="parent"
                                williamchart:layout_constraintTop_toTopOf="parent"
                                williamchart:srcCompat="@drawable/mypardis" />
                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>

                    <com.google.android.material.card.MaterialCardView
                        android:id="@+id/materialCardView"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="8dp"
                        app:cardBackgroundColor="@android:color/transparent"
                        app:cardCornerRadius="32dp"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintHeight_percent="0.25"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintWidth_percent="0.4">

                        <io.alterac.blurkit.BlurLayout xmlns:blurkit="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/blurLayout2"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            blurkit:blk_downscaleFactor="0.30"
                            blurkit:blk_fps="0" />

                        <androidx.constraintlayout.widget.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <ImageView
                                android:id="@+id/imageView2"
                                android:layout_width="0dp"
                                android:layout_height="0dp"
                                android:layout_marginStart="8dp"
                                android:layout_marginTop="8dp"
                                android:layout_marginEnd="8dp"
                                android:layout_marginBottom="8dp"
                                android:elevation="4dp"
                                app:layout_constraintBottom_toBottomOf="parent"
                                app:layout_constraintDimensionRatio="h,15:9"
                                app:layout_constraintEnd_toEndOf="parent"
                                app:layout_constraintStart_toStartOf="parent"
                                app:layout_constraintTop_toTopOf="parent"
                                williamchart:srcCompat="@drawable/mypardis" />
                        </androidx.constraintlayout.widget.ConstraintLayout>

                    </com.google.android.material.card.MaterialCardView>

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

        </androidx.constraintlayout.widget.ConstraintLayout>
        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigation"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="right" />
        <!--app:headerLayout="@layout/navigation_header"
        app:menu="@menu/drawermenu"-->



    </androidx.drawerlayout.widget.DrawerLayout>
</layout>

但是當我將約束轉換為線性時效果很好。 我搜索了很多主題並將 android:fillViewport="true" 放在滾動視圖中,但是如果我將滾動視圖作為根視圖,我的constraintlayout 不會滾動

使用視口為 true 的NestedScrollView

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="700dp">

        </android.support.constraint.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM