[英]Android NavigationView from right side
I have created an Android application, in that I want to open slide menu from right side and when drawer is open I want to slide the view like attached image. 我创建了一个Android应用程序,我想从右侧打开幻灯片菜单,并且当抽屉打开时,我想滑动视图,就像附加的图像一样。
Code: 码:
<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>
For slide view I have used below code, but it's not working 对于幻灯片视图,我使用了以下代码,但无法正常工作
@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();
}
To slide the View
to the left with the drawer, your moveFactor
would be as follows: 要使用抽屉向左滑动View
,您的moveFactor
将如下所示:
float moveFactor = -drawerView.getWidth() * slideOffset;
Do note the negative sign in front of drawerView.getWidth()
. 请注意, drawerView.getWidth()
前面的负号。
The slideOffset
is a fraction that ranges from 0f
to 1f
. slideOffset
是从0f
到1f
的分数。 Multiplying that by the drawer's width gives the actual offset, and negating it, we translate the content View
to the left. 将其乘以抽屉的宽度即可得出实际的偏移量,并将其取反,我们会将内容View
向左平移。
Try This 尝试这个
float moveFactor = drawerView.getWidth() * slideOffset;
container.setTranslationX(moveFactor);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.