(加入显示电量功能)模仿魅族、华为、小米电池续航管理软件, 动态水波纹滚动的圆形小球View

一,效果图:
图一为所做项目效果展示图:

图二为单独这个View的效果图:


二,使用方法:
1,由于是自定义的View,所以需要在attrs.xml里加入如下属性定义:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <attr name="batteryLevel" format="float" />
    <attr name="radius" format="integer" />
    <attr name="flowRadius" format="dimension" />
    <attr name="textColor" format="color" />
    <attr name="textSize" format="dimension" />
    <attr name="flowViewColor" format="color" />

    <declare-styleable name="BatteryView">
        <attr name="batteryLevel" />
        <attr name="radius" />
        <attr name="flowRadius" />
        <attr name="textColor" />
        <attr name="textSize" />
        <attr name="flowViewColor"/>
    </declare-styleable>

</resources>
2,在布局文件中引入:
xmlns:zhangxutong="http://schemas.android.com/apk/res-auto"
<mcxtzhang.weixin521.help.BatteryView
    android:background="@drawable/battery_view_bg_circle"
    android:id="@+id/batteryView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:padding="10dp"
    zhangxutong:flowViewColor="#ffaaffaa"/>
以上自定义的属性,如果我们需要自定义波浪滚动的圆球的颜色,则传入 flowViewColor,否则可完全使用默认属性。默认属性如图一,为半透明白色。

3,定义自定义View:
代码如下图:有详细注释:
package mcxtzhang.weixin521.help;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import mcxtzhang.weixin521.R;
import mcxtzhang.weixin521.utils.TipsUtils;


/**
 * @author zhangxutong
 */
public class BatteryView extends View {
    private Context mContext;
    /**
     * 电池电量
     */
    private float level;
    /**
     * 控件半径
     */
    private int radius;
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值