繁体   English   中英

Android TV:回收站视图不滚动

[英]Android TV: Recycler View is not scrolling

我在 Android TV 上显示了使用 Recycler View 的项目列表。 但是我的列表没有滚动,而是专注于它。 请帮我解决这个问题。

private void initRecyclerView(){
    ArrayList<String> categoryList = (ArrayList<String>) getIntent().getSerializableExtra("categoryList"); 
    RecyclerView recyclerView=(RecyclerView) findViewById(R.id.categoryRecyclerView);
    RecyclerViewAdapter adapter=new RecyclerViewAdapter(this,categoryList);
    System.out.println("investmentRecyclerView array: " + categoryList);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
}

Item 的 layout设置focusable=true

前任。 list_item.xml是 RecycerlView 的项目:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/item_selector"
    android:focusable="true">
    <TextView
        android:id="@+id/topic"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:textColor="#ffffff"
        android:gravity="center"/>
</LinearLayout>

要查看其是否集中将此扇区添加为可绘制,并相应地添加图像:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/black" android:state_pressed="true"/>
    <item android:drawable="@color/black" android:state_selected="true"/>
    <item android:drawable="@color/black" android:state_focused="true"/>

    <item android:drawable="@color/lightblue"></item>
</selector>

感谢您的回复。 这是我的 XML 代码。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:id="@+id/parent_layout"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/countries_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="40dp"
        android:textSize="17sp"
        android:text="Canada" />
</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   <androidx.recyclerview.widget.RecyclerView
       android:id="@+id/recyclerView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:focusable="true"
       android:scrollbars="vertical"></androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>

您必须使用Leanback SDK 中的VerticalGridViewHorizo ntalGridView 而不是RecyclerView

<androidx.leanback.widget.HorizontalGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:lb="http://schemas.android.com/apk/res-auto"
android:id="@+id/row_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
lb:rowHeight="wrap_content"
style="?attr/rowHorizontalGridStyle" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM