短视频源码,每日任务通过刮卡的方式选择,刮卡动画实现的相关代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bk" tools:context=".MainActivity"> <ImageView android:id="@+id/bg" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg"/> <ImageView android:id="@+id/imgv" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/scratch_card"/> </RelativeLayout>
MainActivity.java
package com.example.service; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.text.Html; import android.util.DisplayMetrics; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CalendarView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import android.widget.ImageView; import android.os.Bundle; public class MainActivity extends AppCompatActivity { private ImageView imageView; private Bitmap alterBitmap; private double nX,nY; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView=(ImageView) findViewById(R.id.imgv); Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.scratch_card); alterBitmap=Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig()); DisplayMetrics dm=new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); nX=(double) bitmap.getWidth()/dm.widthPixels; nY=(double) bitmap.getHeight()/dm.heightPixels; Canvas canvas=new Canvas(alterBitmap); Paint paint=new Paint(); paint.setColor(Color.BLACK); paint.setAntiAlias(true); Matrix matrix=new Matrix(); canvas.drawBitmap(bitmap,matrix,paint); imageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { try{ int x=(int) event.getX(); int y=(int) event.getY(); for(int i=-100;i<100;i++){ for(int j=-100;i<100;i++){ if(Math.sqrt((i*i)+(j*j))<=100){ alterBitmap.setPixel((int)(x*nX)+i,(int)(y*nY+90)+j,Color.TRANSPARENT); } } } imageView.setImageBitmap(alterBitmap); }catch (Exception e){ e.printStackTrace(); } return true; } }); } }
以上就是短视频源码,每日任务通过刮卡的方式选择,刮卡动画实现的相关代码, 更多内容欢迎关注之后的文章