Android第三方开源水面波浪波形view:WaveView(电量、能量、容量指示)

来源:互联网 发布:ubuntu安装perl模块 编辑:程序博客网 时间:2024/05/24 02:37


Android第三方开源水面波浪波形view:WaveView(电量、能量、容量指示)

Github上有一个比较有趣的Android第三方开源波形view:WaveView,这种WaveView在一些常见的APP开发中,以水面波浪波形的形象的生动展示手机还剩余多少电量,存储容量还有多少,比较形象直观生动。
如图:


WaveView在github上的项目主页是:https://github.com/john990/WaveView
WaveView首先需要在布局中定义:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:wave="http://schemas.android.com/apk/res-auto"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <com.john.waveview.WaveView        android:id="@+id/wave_view"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="@android:color/white"        wave:above_wave_color="#e53935"        wave:blow_wave_color="#e53935"        wave:progress="60"        wave:wave_height="large"        wave:wave_hz="normal"        wave:wave_length="middle" />    <SeekBar        android:id="@+id/seek_bar"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_gravity="bottom|center_horizontal"        android:layout_marginBottom="20dp"        android:progress="100" /></FrameLayout>


wave:above_wave_color
wave:blow_wave_color
定义波形的颜色(顶部波形平面的下方)。


wave_height
定义波浪的高度。


wave_hz
定义波浪起伏的频率赫兹。



wave_length
定义波浪的长度。


以上几种波浪波形为几种枚举类型。


wave:progress
为整型值,以0-100,100表示最高位波浪,0表示最低波浪。



以一个seekbar调整WaveView的代码为例:

package com.waveview.demo;import android.app.Activity;import android.os.Bundle;import android.widget.SeekBar;import com.john.waveview.WaveView;public class MainActivity extends Activity {    private SeekBar seekBar;    private WaveView waveView;    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        seekBar = (SeekBar) findViewById(R.id.seek_bar);        waveView = (WaveView) findViewById(R.id.wave_view);        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {            @Override            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {                waveView.setProgress(progress);            }            @Override            public void onStartTrackingTouch(SeekBar seekBar) {            }            @Override            public void onStopTrackingTouch(SeekBar seekBar) {            }        });    }}

0 0