[英]How can I implement an Android navigation drawer which slide whole content of activity?
請任何人建議我如何實現導航抽屜滑動完整屏幕的活動。
或者
提前致謝。
***---------
解決方案--------*:** 我找到了解決方案。
使用這個庫很容易使用和處理
您可以嘗試將此布局用於抽屜活動。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp"
>
<RelativeLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</RelativeLayout>
<FrameLayout
android:id="@+id/drawer_holder"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
>
<ListView
android:id="@+id/drawer_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
並像這樣將DrawerLayout.DrawerListener
添加到DrawerLayout
。
drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View view, float slideOffset) {
drawerView.setX(drawerHolder.getWidth() * (1 - slideOffset));
contentLayout.setX(drawerHolder.getWidth() * slideOffset);
}
@Override
public void onDrawerOpened(View view) {
}
@Override
public void onDrawerClosed(View view) {
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
並在添加監聽器后放入此代碼。
drawerLayout.closeDrawer(drawerHolder);
mainDrawerView.setX(0);
contentLayout.setX(0);
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.