相关疑难解决方法(0)

Android TV将焦点转移到RecyclerViews之间

我正在使用以下布局构建Android TV应用: 在此输入图像描述

左侧和右侧的两个列表都是带有垂直LinearLayoutManagers的RecyclerViews,Header视图是静态的.使用D-PAD导航在一个列表中工作正常,但是当从一个列表切换到另一个列表时,存在问题.焦点从list1的项目5移动到list2'项目5.当列表2短的时间少于5项时,它就会失去焦点.

我希望保存最后一个聚焦项目索引,并且当用户导航list1-list2-list1时,具有该索引的项目再次获得焦点并且还防止视图失去焦点.这有什么好的解决方案吗?

所需行为:用户导航到列表顶部并按"向上" - 焦点保持原样,没有任何反应.用户导航到列表的底部并按下"向下" - 焦点停留在原来的位置,没有任何反应.用户从list1导航到list2 - 之前在list2中具有焦点的项目,如果之前没有聚焦,则获得焦点或item0获得焦点.

主要布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/iv_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="false"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="27dp"
        android:layout_marginLeft="48dp"
        android:layout_marginRight="48dp"
        android:layout_marginTop="27dp"
        android:orientation="horizontal"
        >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:orientation="horizontal"
                >

                <ImageView
                    android:id="@+id/iv_poster"
                    android:layout_width="@dimen/episodes_list_item_height"
                    android:layout_height="@dimen/episodes_list_image_width"
                    />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    >

                    <TextView
                        android:id="@+id/tv_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        />

                    <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        >

                        <TextView
                            android:id="@+id/tv_release_date"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            />

                        <TextView
                            android:id="@+id/tv_rating"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"
                            android:drawableLeft="@drawable/ic_star_white_24dp" …
Run Code Online (Sandbox Code Playgroud)

focus d-pad android-tv android-recyclerview

6
推荐指数
1
解决办法
2936
查看次数

标签 统计

android-recyclerview ×1

android-tv ×1

d-pad ×1

focus ×1