Code Monkey home page Code Monkey logo

curtain's Introduction

Curtain

Hex.pm Hex.pm Hex.pm

一个更简洁好用的高亮蒙层库:

  • 一行代码完成某个View,或者多个View的高亮展示
  • 支持基于AapterView(如ListView、GridView) 和RecyclerView 的item以及item中元素的高亮
  • 自动识别圆角背景,也可以自定义高亮形状
  • 高亮区域支持自定义大小、操作灵活
  • 顺应变化,基于Android X
  • 配置简单,导入方便

image

Installation:

dependencies {
    implementation 'com.qw:curtain:0.0.5'
}

Usage:

  • 仅仅是高亮某个View
    private void showCurtain(){
        new Curtain(MainActivity.this)
                .with(findViewById(R.id.textView))
                .show();
    }

image

  • 如果你希望那个view的蒙层区域更大一些:
   private void showCurtain(){
        new Curtain(MainActivity.this)
                .with(findViewById(R.id.textView))
                .withPadding(findViewById(R.id.textView),24)
                .show();
    }
  • 也可以同时高亮多个View:
  private void showCurtain(){
        new Curtain(MainActivity.this)
                .with(findViewById(R.id.textView))
                .with(findViewById(R.id.imageView))
                .show();
    }

image

  • 如果你在蒙层上加上一些其他的元素,可以额外传入View布局:
   private void showCurtain(){
        new Curtain(MainActivity.this)
                .with(findViewById(R.id.textView))
                .setTopView(R.layout.nav_header_main)
                .show();
    }

image

  • 如果你想监听蒙层的展示或者消失的回调:
   private void showCurtain(){
        new Curtain(MainActivity.this)
                .with(findViewById(R.id.imageView))
                .setCallBack(new Curtain.CallBack() {
                    @Override
                    public void onShow(IGuide iGuide) {

                    }

                    @Override
                    public void onDismiss(IGuide iGuide) {

                    }
                }).show();
    }
  • 默认会识别View的背景而生成相关高亮区域的形状,也可以自定形状:
    private void showThirdGuide() {
        new Curtain(SimpleGuideActivity.this)
                .with(findViewById(R.id.btn_shape_custom))
                //圆角
                .withShape(findViewById(R.id.btn_shape_custom), new RoundShape(12))
                //椭圆形
//                .withShape(findViewById(R.id.btn_shape_custom),new CircleShape())
                // 也可继承自 Shape 自己实现形状
//                .withShape(findViewById(R.id.btn_shape_custom), new Shape() {
//                    @Override
//                    public void drawShape(Canvas canvas, Paint paint, HollowInfo info) {
                //draw your shape here
//                    }
//                })
                .show();
    }
  • 在ListView 或者GridView 中使用:
  /**
     * 高亮item
     */
    private void showGuideInItem() {
        View item1 = ViewGetter.getFromAdapterView(listView, 5);
        View item2 = ViewGetter.getFromAdapterView(listView, 2);
        //如果你的View的位置不在屏幕中,返回值为null 需要判空处理
        if (null == item1 || null == item2) {
            return;
        }
        new Curtain(this)
                .with(item1)
                .with(item2)
                .show();
    }

    /**
     * 高亮item中的元素
     */
    private void showGuideInItemChild() {
        View item1 = ViewGetter.getFromAdapterView(listView, 1);
        View item2 = ViewGetter.getFromAdapterView(listView, 3);
        //如果你的View的位置不在屏幕中,返回值为null 需要判空处理
        if (null == item1 || null == item2) {
            return;
        }
        new Curtain(this)
                .withShape(item1.findViewById(R.id.image), new CircleShape())
                .with(item2.findViewById(R.id.tv_text))
                .show();
    }

image

  • 其他一些功能介绍:
    private void showCurtain() {
        new Curtain(MainActivity.this)
                .with(findViewById(R.id.imageView))
                //是否允许回退关闭蒙层
                .setCancelBackPressed(false)
                // 设置蒙层背景颜色
                .setCurtainColor(0x88000000)
                // 设置蒙层出现的动画 默认渐隐
                .setAnimationStyle(R.style.testAnimation)
                .show();
    }

demo 截图:

image

image

Github地址

curtain's People

Contributors

soulqw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.