【发布时间】:2020-01-02 06:55:51
【问题描述】:
我正在将我的活动的视图从上到下移动,问题是,它工作正常并将我的视图从下到上移动但是当转换完成时,它隐藏了视图
这是我的布局:
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/fist_motionlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/fistactivity_motions"
app:showPaths="true">
<include
android:id="@+id/appbar"
layout="@layout/appbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
android:id="@+id/marque"
android:layout_width="match_parent"
android:layout_height="45dp"
app:cardBackgroundColor="#395471"
app:cardCornerRadius="7dp"
app:cardElevation="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
app:layout_constraintTop_toBottomOf="@+id/appbar"
tools:visibility="visible">
</androidx.cardview.widget.CardView>
<FrameLayout
android:id="@+id/fm_firstact_content"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/marque" >
</FrameLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:motion="http://schemas.android.com/tools">
<ConstraintSet android:id="@+id/start_set">
<Constraint
android:id="@+id/fm_firstact_content"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"></Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end_set">
<Constraint
android:id="@+id/fm_firstact_content"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/marque"></Constraint>
</ConstraintSet>
<Transition
android:id="@+id/trans_firstact_fm_content"
app:constraintSetEnd="@id/end_set"
app:constraintSetStart="@id/start_set"
app:duration="2000"></Transition>
</MotionScene>
在活动中,我只是启动它:
MotionLayout ml=vf.findViewById(R.id.fist_motionlayout);
ml.transitionToEnd();
当我运行应用程序时,它将视图从底部移动到顶部并突然变得不可见,奇怪的是当我从另一个活动再次运行活动时,它工作正常并且它不会变得不可见但是如果我关闭应用程序并再次运行它,它会隐藏。每次应用第一次运行时,视图在转换完成后隐藏
这是我的毕业典礼:
implementation 'androidx.appcompat:appcompat:1.2.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
implementation 'androidx.cardview:cardview:1.0.0-alpha01'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
如何解决?
【问题讨论】:
标签: android android-constraintlayout android-transitions android-motionlayout