Android 全屏抽屉fragment,NavigationView
生活随笔
收集整理的這篇文章主要介紹了
Android 全屏抽屉fragment,NavigationView
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、首先是右→左進入動畫 、slide_left.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="800"android:fromXDelta="200%"android:toXDelta="0" /> </set>左→右退出動畫、slide_right.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="800"android:fromXDelta="0"android:toXDelta="200%" /> </set>2、activity 的xml代碼
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical"><TextViewandroid:id="@+id/mainks"android:layout_width="200dp"android:layout_height="100dp"android:gravity="center"android:text="開始"/><TextViewandroid:id="@+id/maingb"android:layout_width="200dp"android:layout_height="100dp"android:gravity="center"android:text="關閉"/></LinearLayout><android.support.design.widget.CoordinatorLayoutandroid:id="@+id/clRootView"android:layout_width="match_parent"android:layout_height="match_parent"></android.support.design.widget.CoordinatorLayout></FrameLayout>3、activity實現方法
boolean ifshowfragment = false;抽屜fragment進入方法yhox
private void showAboutFragment() {getSupportFragmentManager().beginTransaction().disallowAddToBackStack().setCustomAnimations(R.anim.slide_left, R.anim.slide_right).add(R.id.clRootView, MyFragment.newInstance(), MyFragment.TAG).commit();ifshowfragment = true; }抽屜fragment退出方法
public void onFragmentDetached(String tag) {FragmentManager fragmentManager = getSupportFragmentManager();Fragment fragment = fragmentManager.findFragmentByTag(tag);if (fragment != null) {fragmentManager.beginTransaction().disallowAddToBackStack().setCustomAnimations(R.anim.slide_left, R.anim.slide_right).remove(fragment).commitNow();}ifshowfragment = false; }activity返回鍵退出動畫方法:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK&& event.getAction() == KeyEvent.ACTION_DOWN) {if (ifshowfragment) {onFragmentDetached(MyFragment.TAG);return true;}}return super.onKeyDown(keyCode, event); }?
?
demo云盤鏈接:https://pan.baidu.com/s/1t__nXXnfyEUVA24gPOKRAQ
在線回復密碼QQ:1085220040
?
半屏導航fragment實現方法
?
1、添加導航view依賴
compile 'com.android.support:design:28.0.0'?
2、activity代碼:
private NavigationView navigationView; private DrawerLayout drawerLayout; navigationView = (NavigationView)findViewById(R.id.navigation_view); drawerLayout = (DrawerLayout)findViewById(R.id.drawer);?
drawerLayout.openDrawer(navigationView); drawerLayout.closeDrawer(navigationView);效果:
全屏? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?半屏
? ? ? ? ? ? ? ? ? ? ? ? ?
?
總結
以上是生活随笔為你收集整理的Android 全屏抽屉fragment,NavigationView的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机拆机主板6个螺丝,iphone6主
- 下一篇: Android 高德地图在清除所有Mar