在Android项目中实现一个点赞动画?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
目前成都创新互联已为上千余家的企业提供了网站建设、域名、虚拟主机、绵阳服务器托管、企业网站设计、永清网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
具体内容如下
MainActivity.java代码:
package siso.likeanimation;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private DivergeViewSecond mDivergeView;
private Button mBtnStart;
private ImageView mImageView;
private ArrayList mList;
private int mIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBtnStart = (Button)findViewById(R.id.btnStart);
mImageView = (ImageView)findViewById(R.id.iv_start);
mList = new ArrayList<>();
mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.ic_praise_sm1, null)).getBitmap());
mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm2,null)).getBitmap());
mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm3,null)).getBitmap());
mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm4,null)).getBitmap());
mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_praise_sm5,null)).getBitmap());
mList.add(((BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.ic_praise_sm6, null)).getBitmap());
mBtnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mIndex == 5){
mIndex = 0 ;
}
mDivergeView.startDiverges(mIndex);
mIndex ++;
// if (mDivergeView.isRunning()) {
// mDivergeView.stop();
// } else {
//
// }
}
});
mDivergeView = (DivergeViewSecond) findViewById(R.id.divergeView);
mDivergeView.post(new Runnable() {
@Override
public void run() {
mDivergeView.setEndPoint(new PointF(mDivergeView.getMeasuredWidth()/2,0));
mDivergeView.setDivergeViewProvider(new Provider());
}
});
// mDivergeView.start();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(mList != null){
mList.clear();
mList = null;
}
}
class Provider implements DivergeViewSecond.DivergeViewProvider{
@Override
public Bitmap getBitmap(Object obj) {
return mList == null ? null : mList.get((int)obj);
}
}
}
DivergeViewSecond.java代码:
package siso.likeanimation;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
public class DivergeViewSecond extends View implements Runnable{
public static final float mDuration = 0.010F;
public static final int mDefaultHeight = 100;
protected static final long mQueenDuration = 200;
protected final Random mRandom = new Random();
protected ArrayList mDivergeInfos;
protected List
activity_main.xml内容:
<?xml version="1.0" encoding="utf-8"?>
运行结果如图:
关于在Android项目中实现一个点赞动画问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。
网页名称:在Android项目中实现一个点赞动画
网页URL:
http://kswjz.com/article/ghpghg.html