我有一个应用程序,其中我有一个带导航抽屉的列表视图,默认情况下我想让抽屉打开1/3的屏幕,当用户滑动时将完全打开。我该怎么做
答案 0 :(得分:0)
值\ dimens.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="navigation_drawer_width">250dp</dimen>
</resorces>
在xml中定义navigationView
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_actual_home"
app:menu="@menu/activity_actual_home_drawer" />
答案 1 :(得分:0)
您可以获取显示的宽度并设置导航抽屉的宽度
Display display = this.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int displayWidth = size.x;
int displayHeight = size.y;
设置抽屉宽度
ViewGroup.LayoutParams params = drawer.getLayoutParams()
params.width = displayWidth / 3; //calculates 1/3 of the screen width
drawer.setLayoutParams(params);