我有一个DrawerLayout和一个ActionBar,我正在分配一个自定义布局:
mActionBar.setCustomView(new ActionBarContentView(getBaseContext()));
当导航抽屉打开时,我为ActionBar的布局设置动画,使其偏向正在打开的抽屉:
public void onDrawerSlide(View drawerView, float slideOffset) {
slideActivityContent(drawerView,slideOffset);
}
private void slideActivityContent(View drawerView, float slideOffset) {
float moveFactor = (getActivityNetworkListFrameLayout().getWidth() * slideOffset);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActivityContentFrameLayout().setTranslationX(moveFactor);
mActionBar.getCustomView().setTranslationX(moveFactor);
} else {
TranslateAnimation translateAnimation = new TranslateAnimation(mLastTranslate, moveFactor, 0.0f, 0.0f);
translateAnimation.setDuration(0);
translateAnimation.setFillAfter(true);
getActivityContentFrameLayout().startAnimation(translateAnimation);
mActionBar.getCustomView().startAnimation(translateAnimation);
mLastTranslate = moveFactor;
}
}
这在视觉布局方面都按预期工作。但是,我在ActionBar上有3个按钮,当移动操作栏的可视布局时,我仍然可以选择3个按钮。这意味着当导航抽屉打开时,我仍然选择操作栏按钮而不是导航抽屉布局上的按钮。