henryblue / TvRecyclerView

A custom RecyclerView for Android TV end
Apache License 2.0
7 stars 4 forks source link

recyclerView如何失去焦点 #15

Closed liyajun2013 closed 6 years ago

liyajun2013 commented 6 years ago

你好,用了你的框架,感觉很好用,非常感谢。 现在碰到一个问题就是一个横向的recyclerView外面加一个控件,但是recyclerView一直失去焦点

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f9f9f9"
    android:orientation="vertical">

    <app.com.tvrecyclerview.TvRecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_centerInParent="true"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:focusable="true"
        app:focusDrawable="@drawable/default_focus"
        app:isAutoProcessFocus="true" />

    <ImageView
        android:id="@+id/iv_ad"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:focusable="true"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher" />

</LinearLayout>
henryblue commented 6 years ago

我测试了一下, 没有失去焦点,只有滑到最下面,再往下滑动,会失去焦点,因为焦点被ImageView获取。 你可以说的具体一点, 怎样失去焦点的?

liyajun2013 commented 6 years ago

@henryblue 刚刚用你的框架代码试了下,确实没问题。我代码问题我对比了下是用了你的ModuleFocusActivity类中内部类SpaceItemDecoration

 @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                                   RecyclerView.State state) {
//            outRect.bottom = space;
            outRect.top = space;
            outRect.left = space;
        }

这个bottom被我写成了top就有问题了,你的demo也会出现,这个有区别的吗?

henryblue commented 6 years ago

我改了ModuleFocusActivity的outRect.bottom为top, 然后将布局改成你写的, 测试也没问题。你是在什么android什么版本上测的

henryblue commented 6 years ago

虽然问题没复现,但是我发现改了SpaceItemDecoration, module中item的位置不规则, 这部分我已经修改, 是不是这个原因导致的, 你试一下1.1.0版本

liyajun2013 commented 6 years ago

@henryblue 感谢你的帮助,最新的1.1.0版本测试可以了,谢谢