Git Product home page Git Product logo

demo-recyclerviewenteranimation's Introduction

demo-recyclerviewenteranimation's People

Contributors

patrick-elmquist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

demo-recyclerviewenteranimation's Issues

GridRecyclerView No Animation.

Hello,

I found your tutorial on : https://proandroiddev.com/enter-animation-using-recyclerview-and-layoutanimation-part-2-grids-688829b1d29b

I tried implementing in an application where I have a grid recyclerview. However, no animation is executed when the application is started. I tried debugging and saw that

    protected void attachLayoutAnimationParameters(View child, ViewGroup.LayoutParams params,
                                                   int index, int count)

--Update--

The issue I had was that I did not call - scheduleLayoutAnimation().

Grid animation is not working with data binding

You can watch this video
Here is my code and animation resources are the exactly same as yours

 override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val binding = DataBindingUtil.inflate<FragmentMovieListBinding>(inflater, R.layout.fragment_movie_list, container, false)
        initRecyclerView(binding)
        val model = ViewModelProviders.of(this).get(MovieListViewModel::class.java)
        model.listType = listType
        binding.viewModel = model
        getMovieList(binding)
        return binding.root
    }

    private fun getMovieList(binding: FragmentMovieListBinding) {
        binding.viewModel.getMovieList()
                .subscribe({ movieResponse ->
                    movieResponse.results.let {
                        adapter.setMovieList(it)
                        val animation = AnimationUtils.loadLayoutAnimation(activity, R.anim.grid_layout_animation_from_bottom)
                        binding.listRecyclerView.layoutAnimation = animation
                        binding.listRecyclerView.adapter.notifyDataSetChanged()
                        binding.listRecyclerView.scheduleLayoutAnimation()
                    }

                }, { throwable ->
                    Timber.e(throwable)
                })
    }

    private fun initRecyclerView(binding: FragmentMovieListBinding) {
        val manager = GridLayoutManager(activity, 3)
        binding.listRecyclerView.layoutManager = manager
        binding.listRecyclerView.adapter = adapter
    }

class AdvancedRecyclerView : RecyclerView {

    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)

    override fun attachLayoutAnimationParameters(child: View, params: ViewGroup.LayoutParams,
                                                 index: Int, count: Int) {
        val layoutManager = layoutManager
        if (adapter != null && layoutManager is GridLayoutManager) {

            var animationParams: GridLayoutAnimationController.AnimationParameters? = null

            if (params.layoutAnimationParameters == null) {
                // If there are no animation parameters, create new once and attach them to
                // the LayoutParams.
                animationParams = GridLayoutAnimationController.AnimationParameters()
                params.layoutAnimationParameters = animationParams
            }

            // Next we are updating the parameters

            // Set the number of items in the RecyclerView and the index of this item
            animationParams?.count = count
            animationParams?.index = index

            // Calculate the number of columns and rows in the grid
            val columns = layoutManager.spanCount
            animationParams?.columnsCount = columns
            animationParams?.rowsCount = count / columns

            // Calculate the column/row position in the grid
            val invertedIndex = count - 1 - index
            animationParams?.column = columns - 1 - invertedIndex % columns
            animationParams?.row = animationParams!!.rowsCount - 1 - invertedIndex / columns

        } else {
            // Proceed as normal if using another type of LayoutManager
            super.attachLayoutAnimationParameters(child, params, index, count)
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <variable
            name="viewModel"
            type="com.dtunctuncer.todomovielist.ui.discover.movielist.MovieListViewModel" />
    </data>

    <com.dtunctuncer.todomovielist.core.widgets.AdvancedRecyclerView
        android:id="@+id/listRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layoutAnimation="@anim/grid_layout_animation_from_bottom" />
</layout>

Animation executes on older data set

https://github.com/patrick-iv/Enter-animation-demo/blob/7b35deb075d03c9907502ff29e27e3c72beb6368/app/src/main/java/com/patrickiv/demo/enteranimationdemo/fragment/BaseFragment.java#L95

RecyclerView gets data from API call and when data gets populated it gets Animation as expected, but when the user scrolls to end and pagination logic calls for next page data I call runLayoutAnimation() when next page data is available but Animation gets executed on older data set which is already in recyclerview.

I want the Animation to execute only on the new data set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.