我有一个带有折叠工具栏的活动,除了带有菜单项和后退箭头按钮的触摸事件外,一切正常。
如果 Toolbar (android.support.v7.widget.Toolbar) 放在 CollapsingTollbarLayout 之外,一切正常。
据我了解,折叠是从工具栏中抓取触摸事件,并且无法到达,对吗?我尝试将 requestDisallowInterceptTouchEvent 设置为 false,但没有运气。
像这样:
mToolbar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(false);
return false;
}
});
请帮助我了解我错过了什么。非常感谢!
这是我的布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/sub_goals_list_container"
android:layout_width="match_parent"
android:layout_height="210dp"
android:fitsSystemWindows="true"
android:background="@null"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/sub_goals_collapsingToolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:contentScrim="?attr/colorPrimaryDark"
app:titleEnabled="true"
app:toolbarId="@+id/sub_goals_list_toolbar"
app:expandedTitleTextAppearance="@style/TitleSubGoalsStyle"
app:expandedTitleMarginStart="72dp"
app:expandedTitleMarginBottom="115dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:elevation="3dp">
<ImageView
android:id="@+id/bg_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:src="@drawable/bg_create_big_goal"/>
<android.support.v7.widget.Toolbar
android:id="@id/sub_goals_list_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"
app:layout_collapseMode="pin"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="@id/sub_goals_list_container"
android:layout_marginLeft="72dp"
android:layout_marginTop="50dp"
android:paddingRight="8dp"
app:layout_collapseMode="parallax"
style="@style/DetailsOfTheBigGoal"
>
// Some TextView here
</RelativeLayout>
<com.daimajia.numberprogressbar.NumberProgressBar
app:progress_reached_color="@color/darkBlueSea"
app:progress_unreached_color="@color/brightBlue"
app:progress_text_color="@color/darkBlueSea"
app:progress_text_size="14sp"
app:progress_unreached_bar_height="3dp"
app:progress_reached_bar_height="3dp"
android:id="@+id/big_goal_inner_progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_marginLeft="56dp"
android:layout_marginTop="94dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_sub_goal_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@drawable/ic_plus_fab"
app:borderWidth="0dp"
app:layout_anchor="@id/sub_goals_list_container"
app:layout_anchorGravity="bottom|left|end" />
</android.support.design.widget.CoordinatorLayout>
我的菜单代码如下所示:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
onBackPressed();
return true;
case R.id.delete_big_goal:
try {
IntentionDAOHelper.deleteIntention(mBigGoal, mBigGoalsDAO);
} catch (SQLException e) {
e.printStackTrace();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}