我有一个简单的CoordinatorLayout
,其中ConstraintLayout
作为底页和其他2个视图。底页工作正常,但我似乎无法在任何视图上获得触摸事件。
的xml:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<include layout="@layout/app_bar" />
<include layout="@layout/content_main"/>
<View
android:id="@+id/way_finding_pin_background"
android:layout_width="52dp"
android:layout_height="52dp"
android:elevation="4dp"
android:layout_marginStart="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:background="@drawable/way_finding_pin_background"
app:layout_anchor="@+id/way_finding_bar_content"
app:layout_anchorGravity="top|start"
/>
<ImageView
android:id="@+id/way_finding_pin"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginStart="24dp"
android:src="@drawable/ic_add_location"
android:elevation="4dp"
android:clickable="true"
android:focusable="true"
android:duplicateParentState="true"
app:layout_anchor="@+id/way_finding_bar_content"
app:layout_anchorGravity="top|start"
/>
<android.support.constraint.ConstraintLayout
android:id="@+id/way_finding_bar_content"
android:layout_width="match_parent"
android:layout_height="420dp"
android:elevation="3dp"
app:behavior_peekHeight="64dp"
app:behavior_hideable="false"
tools:visibility="visible"
android:background="@android:color/darker_gray"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
的活动:
wayFindingBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "onTouch() bar called with: v = [" + v + "], event = [" + event + "]");
wayFindingPin.onTouchEvent(event);
return true;
}
});
wayFindingPinBkg.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "onTouch() pin background called with: v = [" + v + "], event = [" + event + "]");
wayFindingPin.onTouchEvent(event);
return true;
}
});
wayFindingPin.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Log.d(TAG, "onTouch() pin called with: view = [" + view + "], event = [" + event + "]");
return true;
} else {
return false;
}
}
});
活动中的所有onTouch侦听器都没有被调用过。在这种情况下如何拦截触摸事件?
答案 0 :(得分:0)
我真的不知道为什么会发生,但是“ android:animateLayoutChanges” =“ true”是原因。我没有足够的时间来找出原因。 您应该尝试一下。