简体   繁体   English

处理单击以回收视图父级

[英]Handle click for recycle view parent

I have a recycle view horizontaly which sometimes contains one or two elements and may not cover entire screen. 我有一个水平的回收视图,有时包含一个或两个元素,并且可能不会覆盖整个屏幕。

I want to handle click for the rest of empty space on right but since by default recycler view is match parent the click listener on container does not work. 我想处理右侧剩余空间的单击,但是由于默认情况下,回收站视图与父级匹配,因此容器上的单击侦听器不起作用。

Is it possible to stop recycler taking click entirely and its parent container (say Linear Layout) handle click 是否有可能停止回收商完全点击并使其父容器(例如“线性布局”)点击

<LinearLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
                android:id="@+id/rv_friend_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="@dimen/ad_detail_friend_recycle_min_height" />
</LinearLayout>

I have tried making recycler element as disabled and even whole recycler list clickable and focusable false. 我尝试将回收器元素设置为禁用,甚至整个回收器列表都可点击且可聚焦为false。

Hey the problem lies with the fact that you are not able to set property wrap_content to the width of the recycler view( https://code.google.com/p/android/issues/detail?id=74772 ) 嘿,问题在于您无法将属性wrap_content设置为回收站视图的宽度( https://code.google.com/p/android/issues/detail?id=74772

However there is a workaround for the same available here which is to set a custom layout manager which shall enable you to set the wrap_content property to the recycler-view. 然而,有对同一可用的解决方法在这里是设置一个自定义布局管理器,它应使您可以设置WRAP_CONTENT属性回收站视图。 Now set a click listener on the linear-layout and you are good to go. 现在,在线性布局上设置一个点击监听器,您就可以开始了。

Now, there is another way which i'm not sure will work, but what if you set a onclicklistener on the recycler-view itself??;-) 现在,我不确定还有另一种方法可以使用,但是如果您在回收器视图本身上设置onclicklistener,该怎么办?

感谢新的支持库23.2.0,现在已解决此问题。

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

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