androidkotlinobjectanimator

Why my viewgroup (linear layout) is not animating?


i don't know why my linear layout (ll_header) is not animating even i am getting the proper callbacks on scrolling the recylcer view.

my viewgroup is not even moving from its position

previously i have also worked on object animators many times they were working very fine i am doing same here but my view is not moving at all

i have also tried with static values still it is still in its position

private fun addListener() {
    rv_demo.addOnScrollListener(object : RecyclerView.OnScrollListener() {
        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
            super.onScrolled(recyclerView, dx, dy)

            objectAnimator = ObjectAnimator.ofInt(ll_header,"translationY", dy)

            objectAnimator.start()
        }
    })
}

this is my layout in xml

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:orientation="vertical">

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_demo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    <LinearLayout
            android:id="@+id/ll_header"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="vertical"
            android:background="@android:color/holo_blue_bright"/>

</RelativeLayout>

please help... thanks in advance .


Solution

  • There are two things come to my mind.

    1. translationY is float value. So you should try using ObjectAnimator.ofFloat()
    2. Check whether you somehow disabled animations from developer settings