Android实现引导效果
1.效果
2.使用GuideView框架
GuideView生成引导比较方便,就是一些细节容易忘记,我在工作中使用过几次了,但是这个流程还是不太清晰,所以做个笔记巩固
2.1依赖
implementation 'com.binioter:guideview:1.0.0'
2.2定义一个component
一些概念
public class MyComponent implements Component {
@Override
public View getView(LayoutInflater inflater) {
return null;
}
@Override
public int getAnchor() {
return 0;
}
@Override
public int getFitPosition() {
return 0;
}
@Override
public int getXOffset() {
return 0;
}
@Override
public int getYOffset() {
return 0;
}
}
测试代码:安排一个引导布局,在高亮View的上方,并且左对齐,向左偏移158dp。向上偏移10dp
public class GuideViewDemoComponent implements Component {
@Override
public View getView(LayoutInflater inflater) {
RelativeLayout relativeLayout = (RelativeLayout) inflater.inflate(R.layout.component_guide_view_demo,null);
return relativeLayout;
}
@Override
public int getAnchor() {
return ANCHOR_TOP;
}
@Override
public int getFitPosition() {
return FIT_START;
}
@Override
public int getXOffset() {
return -158;
}
@Override
public int getYOffset() {
return -10;
}
}
2.3在Activity中显示引导效果
GuideBuilder builder = new GuideBuilder();
builder.setTargetView(targetView)
.setHighTargetCorner(UiUtils.dip2px(this,8))
.setHighTargetPadding(UiUtils.dip2px(this,10))
.setOutsideTouchable(true)
.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
@Override
public void onShown() {
}
@Override
public void onDismiss() {
}
})
.setAlpha(128);
builder.addComponent(new GuideViewDemoComponent());
builder.createGuide().show(this);
2.4GuideView的github地址
GuideView的github地址
|