Android progressBar 自定义
来源:互联网 发布:广州增城积分计算法 编辑:程序博客网 时间:2024/06/02 16:46
在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】Android 自定义ProgressBar集锦
- android自定义标题栏progressBar
- android 自定义ProgressBar
- Android 自定义ProgressBar (一)
- android自定义progressbar
- Android 自定义progressbar
- android 自定义progressbar
- Android自定义RatingBar && ProgressBar
- Android 自定义ProgressBar
- Android开发 自定义ProgressBar
- android自定义ProgressBar
- Android中自定义ProgressBar
- 【Android】自定义ProgressBar
- Android 自定义ProgressBar
- android 自定义ProgressBar
- Android progressBar 自定义
- Android 自定义ProgressBar
- android自定义ProgressBar
- vs2012 wp8 应用调试时报错 指定的通信资源(端口) 已由另一个应用程序使
- 证明四点共圆
- spring MVC配置详解
- 电脑眼睛保护色——绿豆沙色
- OTT盒子登堂入室引爆客厅入口之争
- Android progressBar 自定义
- Linux二级文件系统(未完成版本)
- 【格式转换软件】金昌批量转换JPG \BMP \TIFF,可统一尺寸大小
- php 几个比较实用的函数
- opencv读入图像、灰度化、归一化、向量化
- TopCoder SRM 612 DIV1 250 EmoticonsDiv1
- 培养计算思维
- [转]给编程新人的建议
- 如果登录