Android 如何在底部对齐的片段上设置(从底部滑入)视图可见性更改的动画?

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

我有一个片段,它的底部与活动对齐,只占屏幕的一部分。 片段中是视图,单击后显示并隐藏

到目前为止,片段中的根视图具有android:animateLayoutChanges=“true”,但它在动画中处理相同的工件,比如跳跃

    <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)
    
  • 类似的结果

    那么,如何从底部片段滑入,而不跳转视图,而跳转视图位于显示视图上方?就像它是列表中的另一个项目,在一个项目上漫步。

    我看了这个,它给了我我需要的东西(听起来好像你和我试图完成同样的事情。)对我有效的解决方案是使用,传递一个根据你的需要配置的对象。这种方法的优点是可以在Kotlin中编写扩展函数;使您的代码超级可读。我希望这对你有帮助

    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)
    }