Android点赞效果的实现

先看下点赞的效果图

首先添加依赖

api 'com.sackcentury:shinebutton:0.2.0'

xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="100dp"
        android:gravity="center">
    <com.sackcentury.shinebuttonlib.ShineButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:src="@android:color/darker_gray"
        android:id="@+id/bt_like"
        app:btn_color="@android:color/darker_gray"
        app:btn_fill_color="#FF6666"
        app:allow_random_color="false"
        app:enable_flashing="false"
        app:big_shine_color="#FF6666"
        app:click_animation_duration="200"
        app:shine_animation_duration="1500"
        app:shine_turn_angle="10"
        app:small_shine_offset_angle="20"
        app:shine_distance_multiple="1.5"
        app:small_shine_color="#CC9999"
        app:shine_count="8"
        app:siShape="@raw/like"/>

        <com.sackcentury.shinebuttonlib.ShineButton
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:layout_marginLeft="20dp"
            android:src="@android:color/darker_gray"
            android:id="@+id/bt_smile"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#F44336"
            app:allow_random_color="true"
            app:siShape="@raw/smile"/>

        <com.sackcentury.shinebuttonlib.ShineButton
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:layout_centerInParent="true"
            android:id="@+id/bt_star"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#996699"
            app:enable_flashing="true"
            app:shine_size="40dp"
            app:siShape="@raw/star"/>
        <com.sackcentury.shinebuttonlib.ShineButton
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:layout_centerInParent="true"
            android:id="@+id/bt_heart"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#f26d7d"
            app:siShape="@raw/heart"
            android:elevation="10dp" />
    </LinearLayout>
</LinearLayout>

看下属性说明:

属性 Java方法 描述
siShape void setShapeResource(int) 设置原始资源(png)
btn_color void setBtnColor(int) 设置原点颜色
btn_fill_color void setBtnFillColor(int) 单击后设置填充颜色
allow_random_color void setAllowRandomColor(boolean) 允许光泽颜色随机
shine_animation_duration void setAnimDuration(int) 设置光泽动画持续时间
big_shine_color void setBigShineColor (int) 设置大光泽的颜色
click_animation_duration void setClickAnimDuration(int) 设置单击动画持续时间
enable_flashing void enabaleFlashing (boolean) 启用闪光效果
shine_count void setShineCount (int) 按钮周围设置闪耀计数
shine_distance_multiple void setShineDistanceMultiple (float) 设置距离按钮的多个距离
shine_turn_angle void setShineTurnAngle(float) 设置光泽的转角
shine_size void setShineSize (int) 按像素设置光泽大小
small_shine_color void setSmallShineColor(int) 设置小亮泽颜色
small_shine_offset_angle void setSmallShineOffAngle(float) 将小光泽的角度偏移设置为大光泽

初始化控件: 

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ShineButton btLike = (ShineButton) findViewById(R.id.bt_like);
        btLike.init(this);

        ShineButton btSmile = (ShineButton) findViewById(R.id.bt_smile);
        btSmile.init(this);

        ShineButton btHeart = (ShineButton) findViewById(R.id.bt_heart);
        btHeart.init(this);

        ShineButton btStart = (ShineButton) findViewById(R.id.bt_star);
        btStart.init(this);
    }
}

github链接:

https://github.com/ChadCSong/ShineButton

另外github上一些优秀的开源项目,纯干货分享链接:

https://blog.csdn.net/yun382657988/article/details/83303147

猜你喜欢

转载自blog.csdn.net/yun382657988/article/details/83339852