我创建了一个 Android 应用程序,我想从右侧打开幻灯片菜单,当抽屉打开时,我想像附加图像一样滑动视图。
代码:
<android.support.v4.widget.DrawerLayout
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/navigationView_Right_Home"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true" />
</android.support.v4.widget.DrawerLayout>
对于幻灯片视图,我使用了下面的代码,但它不起作用
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
View container = findViewById(R.id.ll);
float moveFactor = (slideOffset - drawerView.getWidth());
container.setTranslationX(moveFactor);
drawer.bringChildToFront(drawerView);
drawer.requestLayout();
}