Open dtunctuncer opened 6 years ago
The one time I ran into something similar it was due to me setting the item view visibility to GONE instead of INVISIBLE at the start, causing the item to not being measured properly and the animation to fail. Perhaps you have some similar scenario in onBindViewHolder in the adapter?
Sorry I do not change any visibility in my code.
class MovieListAdapter(val application: Application) : RecyclerView.Adapter<MovieListAdapter.ViewHolder>() {
private var movieList: List<Movie?>? = null
init {
movieList = emptyList()
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.binding.viewModel.setMovie(movieList?.get(position))
}
override fun getItemCount(): Int = movieList?.size ?: 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = DataBindingUtil.inflate<ItemMovieListBinding>(LayoutInflater.from(parent.context), R.layout.item_movie_list, parent, false)
val viewModel = MovieListAdapterViewModel(application)
binding.viewModel = viewModel
return ViewHolder(binding)
}
fun setMovieList(movieList: List<Movie?>?) {
this.movieList = movieList
notifyDataSetChanged()
}
class ViewHolder(val binding: ItemMovieListBinding) : RecyclerView.ViewHolder(binding.root)
}
class MovieListAdapterViewModel(val app: Application) : AndroidViewModel(app) {
var movie: ObservableField<Movie> = ObservableField()
var picture: ObservableField<Drawable> = ObservableField()
var statusPicture: ObservableField<Drawable> = ObservableField()
private var bindableFieldTarget: BindableFieldTarget? = null
fun setMovie(movie: Movie?) {
bindableFieldTarget = BindableFieldTarget(picture, app.resources, statusPicture)
Picasso.with(app).load(BuildConfig.SMALL_IMAGE_URL + movie?.posterPath).placeholder(R.drawable.animation_progress).error(R.drawable.error).into(bindableFieldTarget)
this.movie.set(movie)
}
fun onClick() {
val intent = Intent(app, MovieActivity::class.java)
intent.putExtra(MovieActivity.ARG_MOVIE, movie.get())
app.startActivity(intent)
}
}
<?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.MovieListAdapterViewModel" />
</data>
<com.dtunctuncer.todomovielist.core.widgets.RectangleLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:onClick="@{() -> viewModel.onClick()}">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:src="@{viewModel.statusPicture}" />
<ImageView
android:id="@+id/posterImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@{viewModel.picture}"
android:transitionName="@string/poster_image_trasition_name" />
</com.dtunctuncer.todomovielist.core.widgets.RectangleLayout>
</layout>
Is the issue just when using Grids? What happens if you switch to a LinearLayoutManager and the regular RecyclerView?
I've never used the Data Binding apis so not sure how/if they might have an effect on the LayoutAnimation.
Sorry for late answer no I haven't tryed it with LinearLayoutManager I think problem is Data Binding
You can watch this video Here is my code and animation resources are the exactly same as yours