SlidingRootNav
介绍:
一个菜单隐藏在主界面底部的抽屉导航。
运行效果:
使用说明:
dependencies
compile 'com.yarolegovich:sliding-root-nav:1.0.1'
-
创建你自己的content_view.xml (example)或者在代码中创建一个view
-
在activity中使用setContentView设置content view
-
创建你的menu.xml (example) 或者用代码创建一个view
-
在onCreate中inject menu,你可以指定content view的过渡动画,也可以使用默认的。
new SlidingRootNavBuilder(this)
.withMenuLayout(R.layout.menu_left_drawer)
.inject();
API
Transformations
可以使用SlidingRootNavBuilder指定 root transformations
new SlidingRootNavBuilder(this)
.withDragDistance(140) //Horizontal translation of a view. Default == 180dp
.withRootViewScale(0.7f) //Content view's scale will be interpolated between 1f and 0.7f. Default == 0.65f;
.withRootViewElevation(10) //Content view's elevation will be interpolated between 0 and 10dp. Default == 8.
.withRootViewYTranslation(4) //Content view's translationY will be interpolated between 0 and 4. Default == 0
.addRootTransformation(customTransformation)
.inject();
上面例子中的customTransformation是一个实现了RootTransformation接口的类,参考 default transformations。
Menu behavior
new SlidingRootNavBuilder(this)
.withMenuOpened(true) //Initial menu opened/closed state. Default == false
.withMenuLocked(false) //If true, a user can't open or close the menu. Default == false.
.withGravity(SlideGravity.LEFT) //If LEFT you can swipe a menu from left to right, if RIGHT - the direction is opposite.
.withSavedState(savedInstanceState) //If you call the method, layout will restore its opened/closed state
.inject();
Controling the layout
inject()返回一个可以控制布局的接口。
public interface SlidingRootNav {
boolean isMenuHidden();
boolean isMenuLocked();
void closeMenu();
void closeMenu(boolean animated);
void openMenu();
void openMenu(boolean animated);
void setMenuLocked(boolean locked);
SlidingRootNavLayout getLayout(); //If for some reason you need to work directly with layout - you can
}
Callbacks
拖拽进度:
builder.addDragListener(listener);
public interface DragListener {
void onDrag(float progress); //Float between 0 and 1, where 1 is a fully visible menu
}
托转状态变化:
builder.addDragStateListener(listener);
public interface DragStateListener {
void onDragStart();
void onDragEnd(boolean isMenuOpened);
}
和DrawerLayout.DrawerListener的兼容:
DrawerListenerAdapter adapter = new DrawerListenerAdapter(yourDrawerListener, viewToPassAsDrawer);
builder.addDragListener(listenerAdapter).addDragStateListener(listenerAdapter);
已下载
0