0

I have fragment with bottom alignment to activity which take only part of screen. In the fragment is view which is shown and hide after click.

Till now root view in fragment had android:animateLayoutChanges="true" but it cases same artifacts in animation like jumps.

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

To improve animation I try:

  1. to use TransitionManager
TransitionManager.beginDelayedTransition(binding.rowContainer)
binding.rowContainer.visibility = View.VISIBLE
  1. put to above custom transition:
<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>

but it causes only that delay slide in.

  1. 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>
    

similar result.

So how to slide in from bottom fragment without jump views which are above appearing view? just like it is a another item in list which is stroll up by one item.

LunaVulpo
  • 3,043
  • 5
  • 30
  • 58

1 Answers1

0

I looked at this answer and it gave me what I needed (which sounds like you and I were trying to accomplish the same thing.) The solution that worked for me was to use View.startAnimation(Animation), passing in an Animation object configured to your needs. The great thing about this approach is you can write an extension function in Kotlin; making your code super readable. I hope this helps you out!

myView.slideUpFromBottom()

fun View.slideUpFromBottom() {
    val animation = TranslateAnimation(
        0f,
        0f,
        height.toFloat(),
        0f
    )
    animation.duration = 500
    animation.fillAfter = true
    startAnimation(animation)
}
Payne Miller
  • 134
  • 1
  • 8