一个富有动感的Sheet(选择器)

Overview

一个富有动感的 Sheet, 先发两张图: 原型.GIF

效果图.gif

Android Arsenal

Android Gems

我的微博

###gradle
/build.gradle

repositories {
    maven {
        url "https://jitpack.io"
    }
}

/app/build.gradle

compile 'com.github.zzz40500:AndroidSweetSheet:1.1.0'

###Usage:


// SweetSheet 控件,根据 rl 确认位置
mSweetSheet = new SweetSheet(rl);

//设置数据源 (数据源支持设置 list 数组,也支持从menu 资源中获取)
mSweetSheet.setMenuList(list);
//根据设置不同的 Delegate 来显示不同的风格.
mSweetSheet.setDelegate(new RecyclerViewDelegate(true));
//根据设置不同Effect来设置背景效果:BlurEffect 模糊效果.DimEffect 变暗效果,NoneEffect 没有效果.
mSweetSheet.setBackgroundEffect(new BlurEffect(8));
//设置菜单点击事件
mSweetSheet.setOnMenuItemClickListener(new SweetSheet.OnMenuItemClickListener() {
    @Override
    public boolean onItemClick(int position, MenuEntity menuEntity1) {

        //根据返回值, true 会关闭 SweetSheet ,false 则不会.
        Toast.makeText(MainActivity.this, menuEntity1.title + "  " + position, Toast.LENGTH_SHORT).show();
        return true;
    }
});

自定义扩展:


// SweetSheet 控件,根据 rl 确认位置
mSweetSheet3 = new SweetSheet(rl);
//定义一个 CustomDelegate 的 Delegate ,并且设置它的出现动画.
CustomDelegate customDelegate = new CustomDelegate(true,
        CustomDelegate.AnimationType.DuangLayoutAnimation);
View view = LayoutInflater.from(this).inflate(R.layout.layout_custom_view, null, false);
//设置自定义视图.
customDelegate.setCustomView(view);
//设置代理类
mSweetSheet3.setDelegate(customDelegate);
//因为使用了 CustomDelegate 所以mSweetSheet3中的 setMenuList和setOnMenuItemClickListener就没有效果了
view.findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mSweetSheet3.dismiss();
    }
});

监听返回

    @Override
    public void onBackPressed() {
 
        if(mSweetSheet.isShow()){

            mSweetSheet.dismiss();
        }
        else{
            super.onBackPressed();
        }
    }

###v1.1(版本说明)

  1. 去掉之前ViewPager 使用FragmentStatePagerAdapter 做为它的适配器.
  • SweetSheet 不支持 LinearLayout 作为它的父控件.

  • setMenuList 设置数据源支持从 List数组和Menu资源的填充.(Menu仅支持一级Menu,因为2级Menu我还没想好怎么展示).

  • setBackgroundEffect(Effect effect) 提供对背景效果的支持,目前提供3种风格: BlurEffect:模糊效果,DimEffect 变暗效果,NoneEffect 没有效果. 你也可以继承Effect扩展背景的效果

  • setDelegate 目前提供了三种风格 RecyclerViewDelegate,ViewPagerDelegate,CustomDelegate.

  • CustomDelegate用于扩展类,你可以使用通过构造方法指定出现动画,通过setCustomView(View v)来设置你的自定义的布局.

  • CustomDelegate中提供了4种类型: DuangLayoutAnimation,DuangAnimation, AlphaAnimation,Custom: 看名字大概就能知道它是什么效果.如果你对前3个效果不满意你就使用 Custom ,然后通过setCustomViewAnimation设置出现效果.

  • CRImageView 内部实现了 Android 5.0上面的CircleReveal效果.使用方法:CRImageView. circularReveal(int centerX, int centerY, float startRadius, float endRadius, long duration, Interpolator interpolator)你可以在你的项目中用上它.

###FAQ 怎么使包括 actionBar 在内的背景也虚化? 使用 一个 FrameLayout或者RelativeLayout 里面使用 ToolBar 来替代 ActionBar 将这个 FrameLayout 或者RelativeLayout作为SweetSheet 的父控件传递进去,

You might also like...
Comments
  • How to disable scroll of custom view

    How to disable scroll of custom view

    Hey I just created a custom view using this. How can I disable the white background that the custom view has and the top bar that is used to pull it up or down?

    I just want the custom view to pop up and pop down thats it. screenshot 2016-01-02 20 14 55

    opened by msaad99 2
  • RecyclerViewDelegate特效无法使用

    RecyclerViewDelegate特效无法使用

    点击之后直接应用崩溃 java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@347765a3 at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1282) at android.graphics.Canvas.setBitmap(Canvas.java:216) at android.view.View.buildDrawingCacheImpl(View.java:14438) at android.view.View.buildDrawingCache(View.java:14339) at android.view.View.getDrawingCache(View.java:14246) at android.view.View.draw(View.java:14933) at android.view.ViewGroup.drawChild(ViewGroup.java:3426) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3219) at android.view.View.draw(View.java:15138) at android.view.ViewGroup.drawChild(ViewGroup.java:3426) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3219) at android.view.View.draw(View.java:15138) at android.view.ViewGroup.drawChild(ViewGroup.java:3426) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3219) at android.view.View.draw(View.java:15138) at android.view.ViewGroup.drawChild(ViewGroup.java:3426) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3219) at android.view.View.draw(View.java:15138) at android.view.ViewGroup.drawChild(ViewGroup.java:3426) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3219) at android.view.View.draw(View.java:15234) at android.widget.FrameLayout.draw(FrameLayout.java:598) at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2650) at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2644) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2557) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

    opened by zengpang 0
  • Crashes

    Crashes

    Clicking rapidly on custom views causes crash. kindly view the log

     Process: .buttomsheet, PID: 26272
      java.lang.IllegalStateException: Cannot start this animator on a detached view!
    at android.view.RenderNode.addAnimator(RenderNode.java:817)
    at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:300)
    at android.view.RenderNodeAnimator.setTarget(RenderNodeAnimator.java:282)
    at android.animation.RevealAnimator.<init>(RevealAnimator.java:37)
    at android.view.ViewAnimationUtils.createCircularReveal(ViewAnimationUtils.java:53)
    at com.mingle.widget.CircleRevealHelper.circularReveal(CircleRevealHelper.java:64)
    at com.mingle.widget.CircleRevealHelper.circularReveal(CircleRevealHelper.java:52)
    at com.mingle.widget.CRImageView.circularReveal(CRImageView.java:84)
    at com.mingle.sweetpick.CustomDelegate$AnimationImp.onEnd(CustomDelegate.java:180)
    at com.mingle.widget.SweetView$4.onAnimationEnd(SweetView.java:126)
    at com.nineoldandroids.animation.ValueAnimator.endAnimation(ValueAnimator.java:1034)
    at com.nineoldandroids.animation.ValueAnimator.access$900(ValueAnimator.java:43)
    at com.nineoldandroids.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:669)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5643)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)```
    opened by AsadAlihp 0
Releases(1.1.0)
Owner
轻微
轻微