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方法描述
siShapevoid setShapeResource(int)设置原始资源(png)
btn_colorvoid setBtnColor(int)设置原点颜色
btn_fill_colorvoid setBtnFillColor(int)单击后设置填充颜色
allow_random_colorvoid setAllowRandomColor(boolean)允许光泽颜色随机
shine_animation_durationvoid setAnimDuration(int)设置光泽动画持续时间
big_shine_colorvoid setBigShineColor (int)设置大光泽的颜色
click_animation_durationvoid setClickAnimDuration(int)设置单击动画持续时间
enable_flashingvoid enabaleFlashing (boolean)启用闪光效果
shine_countvoid setShineCount (int)按钮周围设置闪耀计数
shine_distance_multiplevoid setShineDistanceMultiple (float)设置距离按钮的多个距离
shine_turn_anglevoid setShineTurnAngle(float)设置光泽的转角
shine_sizevoid setShineSize (int)按像素设置光泽大小
small_shine_colorvoid setSmallShineColor(int)设置小亮泽颜色
small_shine_offset_anglevoid 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

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值