自定义progressbar
来源:互联网 发布:js isnullorundefined 编辑:程序博客网 时间:2024/05/17 03:55
本文转自 http://blog.csdn.net/fancylovejava/article/details/21555625
在drawable文件夹中建立如下旋转动画文件
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loading1"
android:pivotX="50%"
android:pivotY="50%" />
其中loading1即为您想用的图片
二 在布局文件中设置progressbar
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/progressbg"
android:indeterminateOnly="true"
android:indeterminateBehavior="repeat"
/>
android 自定义水平的ProgressBar
先看效果图:
代码:
新建drawable
新建一个drawable/progressbarclor
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/progress"
android:drawable="@drawable/common_button_red"/>
</layer-list>
新建drawable/progresssape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="10dp" />
<solid android:color="#ffffff" />
</shape>
布局:
<ProgressBar
android:background="@drawable/progresssape"
android:id="@+id/pb"
android:layout_width="wrap_content"
android:layout_height="10dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:indeterminateOnly="false"
android:max="100"
android:progressDrawable="@drawable/progressbarclor" />
http://winwyf.blog.51cto.com/4561999/857867
- <ProgressBar
- android:id="@+id/progressBar"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="5dip"
- android:layout_toRightOf="@+id/progressBarV"
- android:indeterminate="false"
- android:padding="2dip"
- android:progress="50" />
- <style name="Widget.ProgressBar.Horizontal">
- <item name="android:indeterminateOnly">false</item>
- <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
- <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
- <item name="android:minHeight">20dip</item>
- <item name="android:maxHeight">20dip</item>
- </style>
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@android:id/background">
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#ff9d9e9d"
- android:centerColor="#ff5a5d5a"
- android:centerY="0.75"
- android:endColor="#ff747674"
- android:angle="270"
- />
- </shape>
- </item>
- <item android:id="@android:id/secondaryProgress">
- <clip>
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#80ffd300"
- android:centerColor="#80ffb600"
- android:centerY="0.75"
- android:endColor="#a0ffcb00"
- android:angle="270"
- />
- </shape>
- </clip>
- </item>
- <item android:id="@android:id/progress">
- <clip>
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#ffffd300"
- android:centerColor="#ffffb600"
- android:centerY="0.75"
- android:endColor="#ffffcb00"
- android:angle="270"
- />
- </shape>
- </clip>
- </item>
- </layer-list>
- <?xml version="1.0" encoding="utf-8"?>
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:id="@android:id/progress" android:drawable="@drawable/progressbar" />
- </layer-list>
- <ProgressBar
- android:id="@+id/progressBar1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/progressBar"
- android:layout_margin="5dip"
- android:layout_toRightOf="@+id/progressBarV"
- android:background="@drawable/progress_bg"
- android:indeterminate="false"
- android:indeterminateOnly="false"
- android:maxHeight="20dip"
- android:minHeight="20dip"
- android:padding="2dip"
- android:progress="50"
- android:progressDrawable="@drawable/progress_horizontal1" />
- <item android:id="@android:id/progress">
- <clip>
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#ffffd300"
- android:centerColor="#ffffb600"
- android:centerY="0.75"
- android:endColor="#ffffcb00"
- android:angle="270"
- />
- </shape>
- </clip>
- </item>
- <?xml version="1.0" encoding="utf-8"?>
- <clip
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/drawable_resource"
- android:clipOrientation=["horizontal" | "vertical"]
- android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
- "fill_vertical" | "center_horizontal" | "fill_horizontal" |
- "center" | "fill" | "clip_vertical" | "clip_horizontal"] />
- <item android:id="@android:id/progress">
- <clip
- android:clipOrientation="vertical"
- android:gravity = "bottom">
- <shape>
- <corners android:radius="5dip" />
- <gradient
- android:startColor="#ffffd300"
- android:centerColor="#ffffb600"
- android:centerX="0.75"
- android:endColor="#ffffcb00"
- android:angle="90"
- />
- </shape>
- </clip>
- </item>
- public class Arcs extends View {
- private Paint mArcPaint;
- private Paint mArcBGPaint;
- private RectF mOval;
- private float mSweep = 0;
- private int mSpeedMax = 200;
- private int mThreshold = 100;
- private int mIncSpeedValue = 0;
- private int mCurrentSpeedValue = 0;
- private float mCenterX;
- private float mCenterY;
- private float mSpeedArcWidth;
- private final float SPEED_VALUE_INC = 2;
- ..........
- }
- mArcPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- mArcPaint.setStyle(Paint.Style.STROKE);
- mArcPaint.setStrokeWidth(mSpeedArcWidth);
- // mPaint.setStrokeCap(Paint.Cap.ROUND);
- mArcPaint.setColor(0xff81ccd6);
- BlurMaskFilter mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.INNER);
- mArcPaint.setMaskFilter(mBlur);
- mArcBGPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- mArcBGPaint.setStyle(Paint.Style.STROKE);
- mArcBGPaint.setStrokeWidth(mSpeedArcWidth+8);
- mArcBGPaint.setColor(0xff171717);
- BlurMaskFilter mBGBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.INNER);
- mArcBGPaint.setMaskFilter(mBGBlur);
- @Override
- protected void onSizeChanged(int w, int h, int ow, int oh) {
- super.onSizeChanged(w, h, ow, oh);
- Log.i("onSizeChanged w", w+"");
- Log.i("onSizeChanged h", h+"");
- mCenterX = w * 0.5f; // remember the center of the screen
- mCenterY = h - mSpeedArcWidth;
- mOval = new RectF(mCenterX - mCenterY, mSpeedArcWidth, mCenterX + mCenterY, mCenterY * 2);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- drawSpeed(canvas);
- calcSpeed();
- }
- private void drawSpeed(Canvas canvas) {
- canvas.drawArc(mOval, 179, 181, false, mArcBGPaint);
- mSweep = (float) mIncSpeedValue / mSpeedMax * 180;
- if (mIncSpeedValue > mThreshold) {
- mArcPaint.setColor(0xFFFF0000);
- }
- else {
- mArcPaint.setColor(0xFF00B0F0);
- }
- canvas.drawArc(mOval, 180, mSweep, false, mArcPaint);
- }
- private void calcSpeed() {
- if (mIncSpeedValue < mCurrentSpeedValue) {
- mIncSpeedValue += SPEED_VALUE_INC;
- if (mIncSpeedValue > mCurrentSpeedValue) {
- mIncSpeedValue = mCurrentSpeedValue;
- }
- invalidate();
- }
- else if (mIncSpeedValue > mCurrentSpeedValue) {
- mIncSpeedValue -= SPEED_VALUE_INC;
- if (mIncSpeedValue < mCurrentSpeedValue) {
- mIncSpeedValue = mCurrentSpeedValue;
- }
- invalidate();
- }
- }
- 自定义progressbar
- 自定义ProgressBar
- 自定义Progressbar
- 自定义ProgressBar
- 自定义ProgressBar
- 自定义progressbar
- ProgressBar 自定义
- 自定义ProgressBar
- 自定义ProgressBar
- 自定义ProgressBar
- 自定义ProgressBar
- 自定义ProgressBar
- ProgressBar自定义
- 自定义ProgressBar
- 自定义progressbar
- 自定义ProgressBar
- 自定义progressbar
- 自定义progressbar
- nfs安装与配置
- Android开发之第一个小项目--我的MP3播放器之最后一点结束的话(终)
- Apache和Tomcat整合
- 压缩感知理论+一个经典的算法
- 链表
- 自定义progressbar
- UbuntuSkills
- 简单DMA介绍
- 杭电2124
- 做数字图像处理必备的 图库
- 经典:传统相机标定方法解析…
- RANSAC算法
- CvPoint及CvPoint2D32f
- xx.^2