卡片菜单Android版:coolMenu
jopen
9年前
卡片菜单Android版,由Gal Shir的概念设计而来。
使用说明:
这个library是用 Jitpack发布的,所以在 build.gradle 中添加:
repositories { ... maven { url "https://jitpack.io" } }
添加依赖:
dependencies { compile 'com.github.DxTT:coolMenu:v1.1' }
使用方法类似ViewPager,只需把CoolMenuFrameLayout添加到布局。
在layout.xml中使用的基本例子:
<?xml version="1.0" encoding="utf-8"?> <merge 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" tools:context="com.foocoder.coolmenu.MainActivity" tools:ignore="all" tools:showIn="@layout/activity_main"> <com.dxtt.coolmenu.CoolMenuFrameLayout android:id="@+id/rl_main" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" app:num="four"/> </merge>
这个声明的是卡片的数目,最多5个:
app:num="four"
Like ViewPager,set an Adapter for the CoolMenuFrameLayout view.
就如ViewPager一样,为CoolMenuFrameLayout设置一个Adapter:
coolMenuFrameLayout = $(R.id.rl_main); String[] titles = {"CONTACT", "ABOUT", "TEAM", "PROJECTS"}; titleList = Arrays.asList(titles); //set your titles,which is optional coolMenuFrameLayout.setTitles(titleList); //set your menu icon coolMenuFrameLayout.setMenuIcon(R.drawable.menu2); fragments.add(new Fragment1()); fragments.add(new Fragment2()); fragments.add(new Fragment3()); fragments.add(new Fragment4()); FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { return fragments.get(position); } @Override public int getCount() { return fragments.size(); } }; coolMenuFrameLayout.setAdapter(adapter);