2行代码实现点赞飘心动画
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.moo611:HeartFloatLayout:1.0.1'
}
<atech.com.heartfloat.HeartFloatLayout
android:layout_gravity="center_horizontal"
app:float_duration="5000"
app:scaleable = "false"
android:id="@+id/heart"
android:layout_width="100dp"
android:layout_height="0dp"
android:layout_weight="1"/>
HeartFloatLayout heartFloatLayout = findViewById(R.id.heart);
Button btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
heartFloatLayout.launchHeart();
}
});
heartFloatLayout.setResources(new int[]{R.drawable.a1,R.drawable.a2,R.drawable.a3});
heartFloatLayout.setSize(20,20);
heartFloatLayout.setFloatDuration(5000);
//匀速
heartFloatLayout.setFloatSpeed(new LinearInterpolator());
//先慢后快
heartFloatLayout.setFloatSpeed(new AccelerateInterpolator());
//先快后慢
heartFloatLayout.setFloatSpeed(new DecelerateInterpolator());
heartFloatLayout.setScaleable(false);
<atech.com.heartfloat.HeartFloatLayout
...
app:dWidth="20dp"
app:dHeight="20dp"
app:float_duration="5000"
app:scaleable = "false"/>