我有一个RecyclerView
with a LinearLayoutManager
and an Adapter
:
@Override public int getItemViewType(int position) {
return position == 0? R.layout.header : R.layout.item;
}
Here's header.xml
:
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
/>
我想要实现的是拥有一个hole in the RecyclerView
我可以点击进入后面的任何内容RecyclerView
。我尝试了很多以下属性的组合,但均无济于事:
android:background="@android:color/transparent"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false"
如何使列表中的第一项透明(允许对其后面的任何内容进行触摸事件),但让它仍然占据空间?
您可以设置OnClickListener
/OnTouchListener
你所有的“洞”到视图背后的父级RecyclerView
并委托任何MotionEvent
并触摸该父母的事件ViewGroup
的触摸处理。
TWiStErRob 更新:
class HeaderViewHolder extends RecyclerView.ViewHolder {
public HeaderViewHolder(View view) {
super(view);
view.setOnTouchListener(new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
// http://stackoverflow.com/questions/8121491/is-it-possible-to-add-a-scrollable-textview-to-a-listview
v.getParent().requestDisallowInterceptTouchEvent(true); // needed for complex gestures
// simple tap works without the above line as well
return behindView.dispatchTouchEvent(event); // onTouchEvent won't work
}
});
XML 中没有什么特别需要的,只是简单的视图(问题中没有任何属性)。v.getParent()
is the RecyclerView
那个长方法阻止它在将手指放在“洞”上时启动滚动手势。
我在列表中的“洞”视图也有一个半透明的背景,但这并不重要,因为我们是手动提供触摸的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)