Android实现刮刮卡效果
今天看到一个关于刮刮卡的库,经过测试,感觉还不错,使用方法也比较简单,在这里分享一下。
github地址:https://github.com/D-clock/ScratchView
1.xml布局:
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="test.riven.com.testscratchview.MainActivity">
- <FrameLayout
- android:id="@+id/frame"
- android:layout_width="200dp"
- android:layout_height="200dp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="8dp">
- <!-- content view -->
- <TextView
- android:textColor="#Ff00"
- android:textSize="30sp"
- android:text="一等奖"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- <!-- scratch view -->
- <com.clock.scratch.ScratchView
- android:id="@+id/scratch_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </FrameLayout>
- <Button
- android:id="@+id/btnRest"
- android:layout_below="@+id/frame"
- android:text="Rest"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </RelativeLayout>
2.MianActivity
- public class MainActivity extends AppCompatActivity {
- private ScratchView scratchView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- scratchView = findViewById(R.id.scratch_view);
- /** 设置刮卡时线条的宽度 */
- scratchView.setEraserSize(80);
- /** 设置最大的擦除比例 */
- //scratchView.setMaxPercent(80);
- /** 设置蒙板红色 */
- //scratchView.setMaskColor(0xffff0000);
- /** 设置蒙版水印 */
- //scratchView.setWatermark(R.mipmap.ic_launcher);
- /** 设置刮卡时的监听 */
- scratchView.setEraseStatusListener(new ScratchView.EraseStatusListener() {
- @Override
- public void onProgress(int percent) {
- /** 最大露出面积达80%时,移除蒙版,全部展示 */
- if (percent > 80){
- scratchView.clear();
- }
- }
- @Override
- public void onCompleted(View view) {
- }
- });
- findViewById(R.id.btnRest).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- /** 重新设置 */
- scratchView.reset();
- }
- });
- }
- }
3.api接口
Demo下载
自定义View--刮刮卡
效果图: 原理:最上层是一个(颜色值为#cococo)bitmap,中间是一个画笔在画布上花下用户滑动的路径,最下层是一个背景图片的bitmap(见下图) 具体绘制的代码如下: @Overri...
Android 刮刮卡效果 自定义控件实现
2014年10月18日 4.66MB 下载
Android实现刮刮卡抽奖(上)
自定义View实现刮刮卡界面: import android.annotation.SuppressLint; import android.content.Context; import an...
【Android】刮刮卡实例
前言 日常生活中,抽奖是我们都接触过的一项活动,刚开始的时候是现实中的刮刮卡。后来智能手机上也能刮一刮了。在Android系统要实现刮刮卡的效果,需要用到Bitmap...
Android 实现简单的刮刮乐
上次突发奇想想做个不一样的刮刮乐,参考了大神们的代码。然后,写出了这种效果。 1,先继承TextView/** * Created by Administrator on 2017/2/25. ...
iOS 实现刮刮乐效果demo剑客篇(欢迎提建议和分享经验)
#import "AppDelegate.h" #import "FeelHapplyVC.h" @interface AppDelegate () @end ...
canvas实现刮刮卡,实现canvas擦除
其实这个问题,一直以来都不是问题,因为以前用canvas做的擦除都是针对手机满屏幕来擦除,所以一直没有踩到这个坑~~~ 网络上的擦除效果其实写的都挺泛泛的,没有特别详细的,这里给你们贴一下擦...
自定义View实现刮刮卡效果
继承View实现的一个刮刮卡效果的控件。 使用方法: * 和普通控件的使用方法一样实例化这个View * 使用setCardContent()方法设置设置卡片底层的图片和顶层的遮罩图片,可以使用...
Android刮刮卡的实现
做了几年开发以前都是去看书, 看大神的博客, 看别人的文章, 确实收获了不少, 遇到不会的就查, 看到别人写好的第三方控件就拿过来用 , 使用别人制造的轮子感觉灰常好, 还节省时间, ...
android刮刮卡效果实现
2017年06月10日 27.95MB 下载
iOS开发 刮刮乐效果的实现
引言 我们平时在使用支付宝的时候, 会看到类似彩票刮刮乐的效果。如何实现的呢?下面就直接上代码了... 刮刮乐效果: 1.创建视图: -(void)createSubViews { ...
HTML5 Canvas刮刮卡效果 实例
近年来由于移动设备对HTML5的较好支持,经常有活动用刮奖的效果,最近也在看H5方面的内容,就自己实现了一个,现分享出来跟大家交流。 1、效果 2、原理 原理很简单,就是在刮奖区添加两个can...
Android实现自定义刮刮卡效果View(源码)
2014年12月31日 1.66MB 下载
最新文章
个人分类
归档
热门文章
- android点击查看大图(长按保存图片)
阅读量:3962
- Java中String转MD5
阅读量:2804
- Android使用友盟进行分渠道打包和统计
阅读量:2098
- 解决无法完美卸载office2010的问题
阅读量:2011
- Banner实现广告无限轮播
阅读量:1998
最新评论
- SlideView一个滑动效果库
yhl199514:类和方法正常,xml文件之前不认识app。。。。我alt +enter, 文件里不显示错误了,但...
- SlideView一个滑动效果库
yhl199514:xml文件报错怎么办 error: attribute 'com.example.adminis...
- 自定义ScrollView实现图片...
qq_40090482:在吗,哥们,如果不用ListView 而改为RecyclerView该怎么改,,怎么解决冲突问题
- Banner实现广告无限轮播
dong_junshuai:[reply]XiaoCui9[/reply] 看你喜欢哪个了,各自有各自的好处,如果只是简单的加...
- Banner实现广告无限轮播
XiaoCui9:[reply]XiaoCui9[/reply] Fresco.initialize(this);
0
收藏
评论