Giter VIP home page Giter VIP logo

guideview's Introduction

  • GuideView

  • 本系统能够快速的为一个Activity里的任何一个View控件创建一个遮罩式的导航页。

  • 工作原理

  • 首先它需要一个目标View或者它的id,我们通过findViewById来得到这个View,计算它在屏幕上的区域targetRect,通过这个区域,开始绘制一个覆盖整个Activity的遮罩,可以定义遮罩的颜色和透明度,然而目标View被绘制成透明从而实现高亮的效果。接下来是在相对于这个targetRect的区域绘制一些图片或者文字。我们把这样一张图片或者文字抽象成一个Component接口,设置文字或者图片,所有的图片文字都是相对于targetRect来定义的。可以设定额外的x,y偏移量,可以对遮罩系统设置可见状态的发生变化时的监听回调,可以对遮罩系统设置开始和结束时的动画效,另外,我们可以不对整个Activity覆盖遮罩,而是对某一个View覆盖遮罩。

  • 注意:具体用法参见demo,内附详细注释

  • image

  • usage

    public class SimpleComponent implements Component {
        @Override
        public View getView(LayoutInflater inflater) {
             LinearLayout ll = new LinearLayout(inflater.getContext());
             LinearLayout.LayoutParams param =
                     new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
             ll.setOrientation(LinearLayout.VERTICAL);
             ll.setLayoutParams(param);
             TextView textView = new TextView(inflater.getContext());
             textView.setText(R.string.welcome);
             textView.setTextColor(inflater.getContext().getResources().getColor(R.color.color_white));
             textView.setTextSize(20);
             ImageView imageView = new ImageView(inflater.getContext());
             imageView.setImageResource(R.mipmap.arrow);
             ll.removeAllViews();
             ll.addView(textView);
             ll.addView(imageView);
             ll.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     Toast.makeText(view.getContext(), "引导层被点击了", Toast.LENGTH_SHORT).show();
     
                 }
             });
             return ll;
        }
    
            @Override
            public int getAnchor() {
         		return Component.ANCHOR_BOTTOM;
            }
    
            @Override
            public int getFitPosition() {
         		return Component.FIT_START;
            }
    
            @Override
            public int getXOffset() {
        		    return 30;
            }
    
            @Override
            public int getYOffset() {
         		return 0;
            }
        }
    
     public void showGuideView() {   
         final GuideBuilder builder1 = new GuideBuilder();
         builder1.setTargetView(button1)
                 .setAlpha(150)
                 .setOverlayTarget(true)//设置目标区域是否高亮显示
                 .setOutsideTouchable(false);
         builder1.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
             @Override
             public void onShown() {
                 //  Toast.makeText(MutiGuideViewActivity.this, "show", Toast.LENGTH_SHORT).show();
                 }
             @Override
             public void onDismiss() {
                 button2.post(new Runnable() {
                     @Override
                     public void run() {
                         showGuideView2();
                     }
                 });
                 // Toast.makeText(MutiGuideViewActivity.this, "dismiss", Toast.LENGTH_SHORT).show();
             }
         });
    
         builder1.addComponent(new SimpleComponent());
         Guide guide = builder1.createGuide();
         guide.setShouldCheckLocInWindow(false);
         guide.show(MutiGuideViewActivity.this);
     }
    

guideview's People

Contributors

binioter 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.