`<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize"
android:orientation="vertical"
android:weightSum="2">
<RelativeLayout
android:id="@+id/rll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:descendantFocusability="blocksDescendants"
android:clickable="true">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_benchmarks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:divider="#ffffff"
android:dividerHeight="1dp"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:scrollbars="vertical" />
</RelativeLayout>
</LinearLayout>`
i尝试了各种与降落和关注性的组合,可在不同视图中进行焦点,焦点可构想。
您可以在Intercepttouchevent()上覆盖单击事件,也可以尝试了解视图的事件分布机制
public class CustomRelativeLayout extends RelativeLayout {
private int clickCount = 0;
private static final int REQUIRED_CLICKS = 2; // The number of clicks you need
public CustomRelativeLayout(Context context) {
super(context);
}
public CustomRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomRelativeLayout(
Context context,
AttributeSet attrs,
int defStyleAttr
) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
clickCount++;
if (clickCount >= REQUIRED_CLICKS) {
clickCount = 0; // Reset click count
return false;
}
}
return true;
}
}
最终在布局中使用它