Android 如何在底部对齐的片段上设置(从底部滑入)视图可见性更改的动画?
我有一个片段,它的底部与活动对齐,只占屏幕的一部分。 片段中是视图,单击后显示并隐藏 到目前为止,片段中的根视图具有android:animateLayoutChanges=“true”,但它在动画中处理相同的工件,比如跳跃Android 如何在底部对齐的片段上设置(从底部滑入)视图可见性更改的动画?,android,android-fragments,android-animation,Android,Android Fragments,Android Animation,我有一个片段,它的底部与活动对齐,只占屏幕的一部分。 片段中是视图,单击后显示并隐藏 到目前为止,片段中的根视图具有android:animateLayoutChanges=“true”,但它在动画中处理相同的工件,比如跳跃 <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:layout_height="w
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/buttonsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:focusable="true"
android:descendantFocusability="afterDescendants"
android:visibility="gone"
tools:visibility="visible">
<!-- same buttons -->
</RelativeLayout>
<androidx.appcompat.widget.LinearLayoutCompat
android:orientation="vertical"
android:id="@+id/rowContainer"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- row items -->
</androidx.appcompat.widget.LinearLayoutCompat>
但这只会造成延迟
val slideIn=AnimationUtils.loadAnimation(上下文,底部的R.anim.slide)
binding.rowContainer.startAnimation(slideIn)
myView.slideUpFromBottom()
fun View.slideUpFromBottom() {
val animation = TranslateAnimation(
0f,
0f,
height.toFloat(),
0f
)
animation.duration = 500
animation.fillAfter = true
startAnimation(animation)
}
<transitionSet
xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="together">
<changeBounds android:duration="5000" />
<slide android:duration="5000"
android:slideEdge="bottom"
android:startDelay="0"/>
</transitionSet>
val slideIn = AnimationUtils.loadAnimation(context, R.anim.slide_in_bottom)
binding.rowContainer.startAnimation(slideIn)
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="600"
android:fromYDelta="50%p"
android:toYDelta="0" />
<alpha
android:duration="600"
android:fromAlpha="0.5"
android:toAlpha="1.0" />
</set>
myView.slideUpFromBottom()
fun View.slideUpFromBottom() {
val animation = TranslateAnimation(
0f,
0f,
height.toFloat(),
0f
)
animation.duration = 500
animation.fillAfter = true
startAnimation(animation)
}