Android: MotionLayout не позволяет ребенку расширяться и заполнять экран - PullRequest
0 голосов
/ 03 мая 2020

Я использую фрагмент в MotionLayout, но представление фрагмента не заполняет MotionLayout, даже если установлены все ограничения. Не только фрагмент, даже любое представление, такое как LinearLayout, не расширяется, и я получаю это:

enter image description here

Если я изменю MotionLayout на ConstraintLayout, это работает штрафа и фрагмент заполняет родительский.

Вот мой макет 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">

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"> 

        <androidx.constraintlayout.motion.widget.MotionLayout
            android:id="@+id/motion_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            app:layoutDescription="@xml/scene_drawer"
            tools:context=".activity.MainActivity">  
            <fragment
                android:id="@+id/nav_host"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintLeft_toLeftOf="left" 
                app:defaultNavHost="true"
                app:navGraph="@navigation/main" 
                />
        </androidx.constraintlayout.motion.widget.MotionLayout>

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navView"
            android:layout_width="120dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/navdrawer_menu"
            app:headerLayout="@layout/nav_header"
            />
    </androidx.drawerlayout.widget.DrawerLayout>
</layout>

1 Ответ

0 голосов
/ 04 мая 2020

Я обнаружил, что проблема заключается в том, что в моей сцене движения xml мне нужно было указать ширину и высоту начальных и конечных наборов ограничений в качестве родительского соответствия.

    <?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@+id/start"
        motion:duration="500"
        motion:motionInterpolator="linear"
        />

    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@id/nav_host"
            android:layout_width="match_parent"  
            android:layout_height="match_parent"  
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintWidth_default="percent"
            motion:layout_constraintWidth_percent="1"
            />
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@id/nav_host"
            android:layout_width="match_parent"  
            android:layout_height="match_parent"  
            android:layout_marginLeft="100dp"
            android:scaleX="0.8"
            android:scaleY="0.8"
            android:translationX="100dp"
            motion:layout_constraintWidth_default="percent"
            motion:layout_constraintWidth_percent="1"
            />
    </ConstraintSet>
</MotionScene>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...