安卓.重力变化动画 [英] Android. Animation on gravity change
问题描述
我在另一个框架中有一个FrameLayout.它与中心对齐.
I have a FrameLayout within another one. It is aligned to the center.
不,我想通过更改其重力使其与顶部对齐,但我也想为该更改设置动画.
No I want to align it to top by changing it gravity, but I also want to animate this change.
我已经在这里 https://stackoverflow.com/a/33192335/408780 找到了答案,但是是LayoutTransition.更改使用那里需要API16.
I already found this answer here https://stackoverflow.com/a/33192335/408780, but LayoutTransition.CHANGING using there needs API 16.
我们的应用程序的minSdk为14.关于如何设置重力变化的任何建议?
Our app's however minSdk is 14. Any suggestions how to animate gravity change?
提前谢谢
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bg"
android:scaleType="centerCrop"/>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:animateLayoutChanges="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/container_bg"/>
<EditText
android:layout_gravity="center_vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</FrameLayout>
</FrameLayout>
推荐答案
添加
compile 'com.android.support:transition:25.2.0'
您的应用依赖项. 然后,在更改重力之前添加此行(android.support.transition包中的TransitionManager)
to your app dependencies. Then, add this line before change gravity (TransitionManager from android.support.transition package)
TransitionManager.beginDelayedTransition(parentOfAnimatedView);
例如
mContainer.setOnClickListener(v -> {
TransitionManager.beginDelayedTransition((ViewGroup) mContainer.getParent());
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mContainer.getLayoutParams();
layoutParams.gravity = Gravity.TOP;
mContainer.setLayoutParams(layoutParams);
});
这篇关于安卓.重力变化动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!