Skip to content

xiaotian-freedom/DynamicBattery

Repository files navigation

DynamicBattery

一款可自由动态改动朝向的电池组件

使用方法:

XML中添加如下引用:

<com.storn.view.battery.BigBatteryView
        android:id="@+id/bigBatteryView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:big_bv_body_bg_color="#F3F3F3"
        app:big_bv_body_corner="23dp"
        app:big_bv_body_height="300dp"
        app:big_bv_body_power_color="@color/purple_500"
        app:big_bv_body_width="140dp"
        app:big_bv_header_color="#F3F3F3"
        app:big_bv_header_corner="5dp"
        app:big_bv_header_height="14dp"
        app:big_bv_header_margin="5dp"
        app:big_bv_header_width="56dp"
        app:big_bv_orientation="to_up"
        app:big_bv_percent_text_color="#333333"
        app:big_bv_percent_text_size="26sp"
        app:big_bv_show_power_text="true"
        app:big_bv_text_margin="10dp"
        app:big_bv_tip_text="剩余电量"
        app:big_bv_tip_text_color="#333333"
        app:big_bv_tip_text_size="14sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

代码中调用代码动态改变电池朝向:

//朝上
binding.bigBatteryView.setOrientation(BatteryOrientation.TO_UP)
//朝下
binding.bigBatteryView.setOrientation(BatteryOrientation.TO_DOWN)
//朝左
binding.bigBatteryView.setOrientation(BatteryOrientation.TO_LEFT)
//朝右
binding.bigBatteryView.setOrientation(BatteryOrientation.TO_RIGHT)

想要把电池动起来可调用demo中的如下方法

//开始电量动画
startAnim()

//重置电量动画
resetAnim()

动态图:

GIF

静态图:

图1 图2 图3 图4 图5 图6 图7 图8 图9 图10

About

一款可自由改动朝向的电池组件

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published