FantasySlide
?? DrawerLayout ???,??????????????????????????????????? demo ???
https://raw.githubusercontent.com/mzule/FantasySlide/master/demo.apk
??
????
????
compile 'com.github.mzule.fantasyslide:library:1.0.5'
??
??????? DrawerLayout ??. ??????? (start left end right) ????????
<com.github.mzule.fantasyslide.FantasyDrawerLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/fake" />
<com.github.mzule.fantasyslide.SideBar
android:id="@+id/leftSideBar"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimary"
app:maxTranslationX="66dp">
<!-- ??? SideBar ????-->
</com.github.mzule.fantasyslide.SideBar>
<!-- ???????????????--> </com.github.mzule.fantasyslide.FantasyDrawerLayout>
- ???? FantasyDrawerLayout ??????? DrawerLayout ?????
- SideBar ???????????SideBar ????????? vertical ? LinearLayout ????
- ????????????????? hover ??, hover ??????? view ? pressed ??? true????? Listener ???, ?????????
- ???? https://github.com/mzule/FantasySlide/blob/master/app/src/main/res/layout/activity_main.xml
??
maxTranslationX
???? maxTranslationX ?????????????????????? Transformer ?????
<com.github.mzule.fantasyslide.SideBar ...
app:maxTranslationX="88dp">
???????????? maxTranslationX ?????????? maxTranslationX ????
Listener
???? Listener ????????????
SideBar leftSideBar = (SideBar) findViewById(R.id.leftSideBar);
leftSideBar.setFantasyListener(new SimpleFantasyListener() {
@Override
public boolean onHover(@Nullable View view) {
return false;
}
@Override
public boolean onSelect(View view) {
return false;
}
@Override
public void onCancel() {
}
}
);
- Hover ???????????????????????? move. ??? hover ??????? view ? pressed ??? true. ?? onHover(View) ???? true ?????????
- Select ?? hover ???????????? select ????????????? view ? onClick ????? onSelect(View) ???? true ?????????
- Cancel ?????????????? view ?? select ????? cancel?????????
Transformer
??????? Transformer ?????????????????????????? ViewPager ? PageTransformer.
class DefaultTransformer implements Transformer {
private float maxTranslationX;
DefaultTransformer(float maxTranslationX) {
this.maxTranslationX = maxTranslationX;
}
@Override
public void apply(ViewGroup sideBar, View itemView, float touchY, float slideOffset, boolean isLeft) {
float translationX;
int centerY = itemView.getTop() + itemView.getHeight() / 2;
float distance = Math.abs(touchY - centerY);
float scale = distance / sideBar.getHeight() * 3; // ???????? sideBar ? 1/3 ??
if (isLeft) {
translationX = Math.max(0, maxTranslationX - scale * maxTranslationX);
}
else {
translationX = Math.min(0, maxTranslationX - scale * maxTranslationX);
}
itemView.setTranslationX(translationX * slideOffset);
}
}
??
??????? dribbble. https://dribbble.com/shots/2269140-Force-Touch-Slide-Menu ?????
???demo ?? MainActivity ??????????????????????????????
??
Apache License 2.0
???
???????????????????
- ? issue
- ???? http://weibo.com/mzule
- ???? https://mzule.github.io/
- ?? "mzule".concat("4j").concat("@").concat("gmail.com")