android消息循环滚动条,Android电池电量进度条,上下滚动图
⽚的进度条(batt。。。
jquery下载文件进度条最近,制作⼀个app,需要模拟⼀个电池电量的进度条,根据电量多少来设置百分⽐,进度条不断上下滚动,就像平时⼿机充电⼀样的电池电量进度条。我就⾃定义view实现了电量进度条。修改图⽚就可以达到⾃⼰想要的效果
⼀、⾃定义View,Battery.java,循环刷新界⾯,两张图⽚上下滚动,达到不断向右移动的效果。挺有意思的
开源ip地址管理系统ample.battery;
t.Context;
t.res.Resources;
aphics.Bitmap;
aphics.Canvas;
aphics.Color;
aphics.Paint;
aphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
public class Battery extends View {
public float currentX = 80;
public float currentY = 80;
private float secondY = 80;
private Paint mPaint = new Paint();
private Context mContext;
private Handler mHandler;小程序搭建是什么意思
private Bitmap mBmp;
private int speedTime = 20;
private float with = 200;
private float height = 50;
private float percentage = 0.5f;
public Battery(Context context) {
super(context);
this.mContext = context;
}
public Battery(Context context, AttributeSet set) {
super(context, set);
this.mContext = context;
init();
}
public void onDraw(Canvas canvas) {
with = Width();
js模板引擎height = Height();
mPaint.setColor(Color.BLUE);
Resources res = Resources(); BitmapDrawable bmpDraw = (BitmapDrawable) res .getDrawable(R.drawable.loading_pic);
mBmp = Bitmap();
canvas.clipRect(0, 0, with*percentage, height); canvas.drawBitmap(mBmp, 0, currentY, mPaint); canvas.drawBitmap(mBmp, 0, secondY, mPaint);
}
private void init() {
percentage = 0;
mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
currentX ++;
currentY ++;
if (mBmp != null && currentY > Height()){ currentY = -Height();
}
if (mBmp != null){
secondY = Height();
if (secondY >= Height()){
secondY = Height();
}
}
percentage = percentage + 0.003f;
if (percentage > 1){
percentage = 0;
}
// 每次计算后都发送消息进⼊下⼀次循环,并刷新界⾯mHandler.sendEmptyMessageDelayed(1, speedTime); postInvalidate();
break;
}
super.handleMessage(msg);
postInvalidate();
}
};
// ⾸次循环刷新界⾯
mHandler.sendEmptyMessageDelayed(1, speedTime); }
}学计算机组成原理前先学啥
⼆、MainActivity
ample.battery;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) { Create(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
三、activity_main
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center" >
android:layout_width="300dp"
android:layout_height="10dp" android:layout_gravity="center" android:gravity="center" android:padding="10dp" />四、附图⽚效果
威尔士和英格兰比赛结果
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论