日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 全屏抽屉fragment,NavigationView

發布時間:2023/12/10 Android 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。