向右滑動展示抽屜布局:FlowingDrawer

fefed 9年前發布 | 18K 次閱讀 Android開發 移動開發 FlowingDrawer

Showcase

向右滑動展示抽屜布局, 并具有流動的效果。

下載

Include the following dependency in your build.gradle file.

Gradle:

    repositories {
        jcenter()
    }

    dependencies {
        compile 'com.mxn.soul:flowingdrawer-core:1.1.0'
    }

V1.1

用法

For a working implementation of this project see theapp/folder.

MainActivity:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
           ....
        mLeftDrawerLayout = (LeftDrawerLayout) findViewById(R.id.id_drawerlayout);
        FragmentManager fm = getSupportFragmentManager();
        MyMenuFragment mMenuFragment = (MyMenuFragment) fm.findFragmentById(R.id.id_container_menu);
        FlowingView mFlowingView = (FlowingView) findViewById(R.id.sv);
        if (mMenuFragment == null) {
            fm.beginTransaction().add(R.id.id_container_menu, mMenuFragment = new MyMenuFragment()).commit();
        }
        mLeftDrawerLayout.setFluidView(mFlowingView);
        mLeftDrawerLayout.setMenuFragment(mMenuFragment);
        ...
    }

activity_main.xml:

   <com.mxn.soul.flowingdrawer_core.LeftDrawerLayout
        android:id="@+id/id_drawerlayout"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        >

        <!--content-->
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
        </android.support.design.widget.CoordinatorLayout>

        <!--menu-->
        <RelativeLayout
            android:layout_width="280dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:clipChildren="false"
            >
            <com.mxn.soul.flowingdrawer_core.FlowingView
                android:id="@+id/sv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
            <FrameLayout
                android:id="@+id/id_container_menu"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_marginRight="25dp"
                android:paddingRight="10dp"
                />
        </RelativeLayout>

    </com.mxn.soul.flowingdrawer_core.LeftDrawerLayout>

  • use LeftDrawerLayout as the root of xml.

  • The root has two child, first for content,second for menu.

  • menu'root alse has two child , first for FlowingView to display flowing effects,second for fragment .

  • fragment need to has a 'marginRight', for example 25dp. marginRight here is important . 'marginRight' have effect on drawer's elasticity. The more 'marginRight' is the more elastic. Try to set '10dp', '25dp' ,'50dp' to see the difference.

  • make the fragment of menu extends MenuFragment.

  • pay attention to MenuFragment's onCreateView: return setupReveal(root) ;

      @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_menu, container,
                    false);
            .......
            return  setupReveal(view) ;
        }

  • in MenuFragment'xml ,add 'android:background="@android:color/transparent" '

  • in MainActivity,use

mMenuFragment = new MyMenuFragment();
mLeftDrawerLayout.setFluidView(mFlowingView);
mLeftDrawerLayout.setMenuFragment(mMenuFragment);

項目主頁:http://www.baiduhome.net/lib/view/home/1445865683804

 本文由用戶 fefed 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!