心形点赞动画的实现

    xiaoxiao2026-05-12  8

    https://github.com/tyrantgit/HeartLayout

    In your build.gradle:

    dependencies { compile 'tyrant:heartlayout:1.0.1' } HeartLayout heartLayout = ...; heartLayout.addHeart(color); heartLayout.addHeart(color,heartResId,heartBorderResId);

    demo中的代码

    public class MainActivity extends Activity { private Random mRandom = new Random(); private Timer mTimer = new Timer(); private HeartLayout mHeartLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mHeartLayout = (HeartLayout) findViewById(R.id.heart_layout); mTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { mHeartLayout.post(new Runnable() { @Override public void run() { mHeartLayout.addHeart(randomColor()); } }); } }, 500, 200); } @Override protected void onDestroy() { super.onDestroy(); mTimer.cancel(); } private int randomColor() { return Color.rgb(mRandom.nextInt(255), mRandom.nextInt(255), mRandom.nextInt(255)); } }

    对心形位置进行设置的位置为 /heartlayout/src/main/res/values/dimens.xml

    转载请注明原文地址: https://ju.6miu.com/read-1309590.html
    最新回复(0)