I'm using a RecyclerView with LinearLayout Manager and Horizontal orientation. It's to be used on a TV app, so it needs to be navigated with the dpad. But whenever I go do the end and come back it get stuck on the last one. See photo:
The selected ItemView is the first, but it won't go to the center. if you go to the right and the come back it will show fully.
the code:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="320dp"
app:layout_constraintBottom_toTopOf="@+id/tv_mini_player_view_placeholder"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/carrier_image_card"
app:layout_constraintVertical_bias="0.10">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/margin_start_tv_home"
android:background="@null"
android:clipToPadding="false"
android:orientation="horizontal"
android:padding="@dimen/margin_medium_big"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:context=".android.screens.auth.SelectCarrierActivity"
tools:listitem="@layout/imagecardview_station" />
</androidx.core.widget.NestedScrollView>
One little thing I observed is the layout World Hits didn't adjust the label size. When selected these layouts show a description which makes the transparent grey box larger to acommodate. It's a "View.GONE" change on the description label. So the last selected layout the description disappeared but the layout didn't readjusted. The code for the View Holder part is below:
inner class StationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val mainImageView: ImageView by lazy { itemView.findViewById<ImageView>(R.id.main_image) }
val titleView: TextView by lazy { itemView.findViewById<TextView>(R.id.title_text) }
val descriptionView: TextView by lazy { itemView.findViewById<TextView>(R.id.description_text) }
init {
val frameLayout = itemView.findViewById<FrameLayout>(R.id.frame_layout)
val cardView = itemView.findViewById<FrameLayout>(R.id.cardview)
cardView.apply {
isFocusable = true
isFocusableInTouchMode = true
onFocusChangeListener = View.OnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
AbstractCardPresenter.animateScaleUp(cardView as View)
frameLayout.background = itemView.context.resources.getDrawable(R.drawable.card_border)
descriptionView.visibility = View.VISIBLE
} else {
AbstractCardPresenter.animateScaleDown(cardView as View)
frameLayout.background = null
descriptionView.visibility = View.GONE
}
}
}
itemView.onAttachStateChangeListener {
onViewAttachedToWindow {
if (adapterPosition == 0) {
cardView.requestFocus()
}
}
}
}
}