导航:首页 > 操作系统 > android好看进度条

android好看进度条

发布时间:2022-05-14 23:00:55

⑴ 长按如何使进度条变化android

通过MediaPlayer调节。
系统自带的进度条的颜色比较单调,实际开发中使用较少,可以自定义进度条背景,新建一个progressbarbg.xml文件。gradient可以设置进度条的渐变色,android:endColor和android:startColor可以设置渐变开始和结束的颜色。定义完成以后,便可以使用。
在音乐进度,网络下载时,需动态加载进度条,默认情况下,设置进度条,使用setProgress即可。但有时除了动态设置进度,仍需要动态设置进度条颜色通过MediaPlayer播放音乐并获取进度,设置进度。

⑵ Android 自定义进度条,通过canvas怎么画一个进度条

现在很多手机版网页,或者比较高版本的页面中,经常碰到一中圆形的百分比进度效果这个其实用HTML5中的SVG实现起来比较容易而且逼格看起来比较高使用方法:1、将head中的样式复制到你的样式表中2、将body中的代码部分拷贝过去即可

⑶ android 绘制进度条

看起来代码挺长,其实都是在获取自定义属性,没什么技术含量。
宽度不变,所以的自定义属性不涉及宽度,高度呢,只考虑不是EXACTLY的情况(用户明确指定了,就不管了),根据padding和进度条宽度算出自己想要的,如果非EXACTLY下,进行exceptHeight封装,传入给控件进行测量高度。

横向的滚动条绘制肯定需要一些属性,比如已/未到达进度的颜色、宽度,文本的颜色、大小等。
本来呢,我是想通过系统ProgressBar的progressDrawable,从里面提取一些属性完成绘制需要的参数的。但是,最终呢,反而让代码变得复杂。所以最终还是改用自定义属性。 说道自定义属性,大家应该已经不陌生了。

1、
1、自定义属性
values/attr_progress_bar.xml:

[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="">
<attr name="progress_unreached_color" format="color" />
<attr name="progress_reached_color" format="color" />
<attr name="progress_reached_bar_height" format="dimension" />
<attr name="progress_unreached_bar_height" format="dimension" />
<attr name="progress_text_size" format="dimension" />
<attr name="progress_text_color" format="color" />
<attr name="progress_text_offset" format="dimension" />
<attr name="progress_text_visibility" format="enum">
<enum name="visible" value="0" />
<enum name="invisible" value="1" />
</attr>
</declare-styleable>

<declare-styleable name="RoundProgressBarWidthNumber">
<attr name="radius" format="dimension" />
</declare-styleable>

</resources>
2、构造中获取

[java] view plain
public class extends ProgressBar
{

private static final int DEFAULT_TEXT_SIZE = 10;
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;

/**
* painter of all drawing things
*/
protected Paint mPaint = new Paint();
/**
* color of progress number
*/
protected int mTextColor = DEFAULT_TEXT_COLOR;
/**
* size of text (sp)
*/
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);

/**
* offset of draw progress
*/
protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);

/**
* height of reached progress bar
*/
protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);

/**
* color of reached bar
*/
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
/**
* color of unreached bar
*/
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
/**
* height of unreached progress bar
*/
protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
/**
* view width except padding
*/
protected int mRealWidth;

protected boolean mIfDrawText = true;

protected static final int VISIBLE = 0;

public (Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}

public (Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);

setHorizontalScrollBarEnabled(true);

obtainStyledAttributes(attrs);

mPaint.setTextSize(mTextSize);
mPaint.setColor(mTextColor);

}

/**
* get the styled attributes
*
* @param attrs
*/
private void obtainStyledAttributes(AttributeSet attrs)
{
// init values from custom attributes
final TypedArray attributes = getContext().obtainStyledAttributes(
attrs, R.styleable.);

mTextColor = attributes
.getColor(
R.styleable._progress_text_color,
DEFAULT_TEXT_COLOR);
mTextSize = (int) attributes.getDimension(
R.styleable._progress_text_size,
mTextSize);

mReachedBarColor = attributes
.getColor(
R.styleable._progress_reached_color,
mTextColor);
mUnReachedBarColor = attributes
.getColor(
R.styleable._progress_unreached_color,
DEFAULT_COLOR_UNREACHED_COLOR);
mReachedProgressBarHeight = (int) attributes
.getDimension(
R.styleable._progress_reached_bar_height,
mReachedProgressBarHeight);
mUnReachedProgressBarHeight = (int) attributes
.getDimension(
R.styleable._progress_unreached_bar_height,
mUnReachedProgressBarHeight);
mTextOffset = (int) attributes
.getDimension(
R.styleable._progress_text_offset,
mTextOffset);

int textVisible = attributes
.getInt(R.styleable._progress_text_visibility,
VISIBLE);
if (textVisible != VISIBLE)
{
mIfDrawText = false;
}
attributes.recycle();
}

3、onMeasure
刚才不是出onDraw里面写写就行了么,为什么要改onMeasure呢,主要是因为我们所有的属性比如进度条宽度让用户自定义了,所以我们的测量也得稍微变下。

[java] view plain
@Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
{
int heightMode = MeasureSpec.getMode(heightMeasureSpec);

if (heightMode != MeasureSpec.EXACTLY)
{

float textHeight = (mPaint.descent() + mPaint.ascent());
int exceptHeight = (int) (getPaddingTop() + getPaddingBottom() + Math
.max(Math.max(mReachedProgressBarHeight,
mUnReachedProgressBarHeight), Math.abs(textHeight)));

heightMeasureSpec = MeasureSpec.makeMeasureSpec(exceptHeight,
MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

}

测量完,就到我们的onDraw了~~~

⑷ Android类似于带文本的进度条的效果怎么实现

载一个自定义的loading_process_dialog_anim
调用的方法:
[mw_shl_code=java,false]
public void showRoundProcessDialog(Context mContext, int layout)
{
OnKeyListener keyListener = new OnKeyListener()
{
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_SEARCH)
{
return true;
}
return false;
}
};

mDialog = new AlertDialog.Builder(mContext).create();
mDialog.setOnKeyListener(keyListener);
mDialog.show();
// 注意此处要放在show之后 否则会报异常
mDialog.setContentView(layout);
}[/mw_shl_code]

XML:
[mw_shl_code=java,false]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >

<ProgressBar
android:id="@+id/loading_process_dialog_progressBar"
android:layout_width="33dp"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="@anim/loading" />

</LinearLayout>[/mw_shl_code]

loading.xml:
[mw_shl_code=java,false]<?xml version="1.0" encoding="utf-8"?>
<animation-list android:oneshot="false"
xmlns:android="">
<item android:ration="250" android:drawable="@drawable/loading_01" />
<item android:ration="250" android:drawable="@drawable/loading_02" />
<item android:ration="250" android:drawable="@drawable/loading_03" />
<item android:ration="250" android:drawable="@drawable/loading_04" />
<item android:ration="250" android:drawable="@drawable/loading_05" />
<item android:ration="250" android:drawable="@drawable/loading_06" />
<item android:ration="250" android:drawable="@drawable/loading_07" />
</animation-list> [/mw_shl_code]

⑸ android 怎么使水平进度条动起来 最好有个例子 我是新手

进度条的操作你应该会的吧。
例子网上其实有很多,我大致说一下。

首先你要写一个线程,然后循环i从1开始,i++,一直到100
然后去修改你主线程的进度条
这样你的进度条就动起来了!当到100的时候,传一个intent 跳转activity

⑹ Android开发怎么自定义绘制如下图中这种进度条急需!在线等!

一)变换前背景

先来看看progressbar的属性:
1. <ProgressBar
2. android:id="@+id/progressBar"
3. style="?android:attr/progressBarStyleHorizontal"
4. android:layout_width="match_parent"
5. android:layout_height="wrap_content"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:indeterminate="false"
9. android:padding="2dip"
10. android:progress="50" />
根据style="?android:attr/progressBarStyleHorizontal",我们找到源码中的style.xml
1. <style name="Widget.ProgressBar.Horizontal">
2. <item name="android:indeterminateOnly">false</item>
3. <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
4. <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
5. <item name="android:minHeight">20dip</item>
6. <item name="android:maxHeight">20dip</item>
7. </style>
看到
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
木有,继续发掘源码,找到drawable下面的progress_horizontal.xml,这就是我们今天的主角了:
1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
2.
3. <item android:id="@android:id/background">
4. <shape>
5. <corners android:radius="5dip" />
6. <gradient
7. android:startColor="#ff9d9e9d"
8. android:centerColor="#ff5a5d5a"
9. android:centerY="0.75"
10. android:endColor="#ff747674"
11. android:angle="270"
12. />
13. </shape>
14. </item>
15.
16. <item android:id="@android:id/secondaryProgress">
17. <clip>
18. <shape>
19. <corners android:radius="5dip" />
20. <gradient
21. android:startColor="#80ffd300"
22. android:centerColor="#80ffb600"
23. android:centerY="0.75"
24. android:endColor="#a0ffcb00"
25. android:angle="270"
26. />
27. </shape>
28. </clip>
29. </item>
30.
31. <item android:id="@android:id/progress">
32. <clip>
33. <shape>
34. <corners android:radius="5dip" />
35. <gradient
36. android:startColor="#ffffd300"
37. android:centerColor="#ffffb600"
38. android:centerY="0.75"
39. android:endColor="#ffffcb00"
40. android:angle="270"
41. />
42. </shape>
43. </clip>
44. </item>
45.
46. </layer-list>
看到android:id="@android:id/progress"木有,看到android:id="@android:id/secondaryProgress"木有
把这个文件复制到自己工程下的drawable,就可以随心所欲的修改shape的属性,渐变,圆角等等
那么怎么放一个图片进去呢,ok,新建progress_horizontal1.xml:
1. <?xml version="1.0" encoding="utf-8"?>
2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3.
4. <item android:id="@android:id/progress" android:drawable="@drawable/progressbar" />
5.
6. </layer-list>
在android:drawable中指定你处理好的图片
然后回到布局中
1. <ProgressBar
2. android:id="@+id/progressBar1"
3. android:layout_width="match_parent"
4. android:layout_height="wrap_content"
5. android:layout_below="@+id/progressBar"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:background="@drawable/progress_bg"
9. android:indeterminate="false"
10. android:indeterminateOnly="false"
11. android:maxHeight="20dip"
12. android:minHeight="20dip"
13. android:padding="2dip"
14. android:progress="50"
15. android:progressDrawable="@drawable/progress_horizontal1" />
android:background="@drawable/progress_bg"指定背景
android:progressDrawable="@drawable/progress_horizontal1"前景使用上面的progress_horizontal1

要是还不行

你来我们群里说吧

这里是开发者互相学习交流的 有大神

让他们给你解释你的疑问 号 码look at my n a m e.....

⑺ android 怎么自定义绘制如下图中这种进度条

下面是安卓学习手册中实现各种进度条的截图:

要想看各种进度条的实现代码和文档,直接去360手机助手中下载安卓学习手册,例子文档随便看。

1、说明

在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度。一个进度条也可不确定其进度。在不确定模式下,进度条显示循环动画。这种模式常用于应用程序使用任务的长度是未知的。

2、XML重要属性

android:progressBarStyle:默认进度条样式

android:progressBarStyleHorizontal:水平样式

3 重要方法

getMax():返回这个进度条的范围的上限

getProgress():返回进度

getSecondaryProgress():返回次要进度

incrementProgressBy(int diff):指定增加的进度

isIndeterminate():指示进度条是否在不确定模式下

setIndeterminate(boolean indeterminate):设置不确定模式下

setVisibility(int v):设置该进度条是否可视

4 重要事件

onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件

5进度条的样式

Widget.ProgressBar.Horizontal长形进度

Androidxml 布局:

<ProgressBar

android:id="@+id/progress_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

style="@android:style/Widget.ProgressBar.Horizontal "

/>

源码:

private ProgressBar mProgress;

private int mProgressStatus=0;

private Handler mHandler=newHandler();

@Override

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mProgress=(ProgressBar)findViewById(R.id.progress_bar);

new Thread(new Runnable(){

@Override

public void run(){

while(mProgressStatus<100){

mProgressStatus=doWork();

mHandler.post(new Runnable(){

@Override

public void run(){

mProgress.setProgress(mProgressStatus);

}

});

}

}

}).start();

}

效果图:

带第二进度的进度条

xml配置如下:

<ProgressBar

android:id="@+id/progress_bar_with_second"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="40"

android:secondaryProgress="70"

android:paddingTop="20dp"

android:paddingBottom="20dp"/>

这里我们设置了初始的进度为40,android:progress的值在mini和max之间即mini<=progressvalue<=max

设置了第二进度条的进度值为70,该值也在mini和max之间。

效果如下:

不确定模式进度条

xml配置文件:

<ProgressBar

android:id="@+id/progress_bar_indeterminate"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:indeterminate="true"

android:indeterminateBehavior="cycle"

android:paddingBottom="20dp"

android:paddingTop="20dp"

android:progress="40" />

这里通过android:indeterminate="true"设置了当前为无模式进度条

效果如图:

普通圆形进度:Widget.ProgressBar.Inverse

<ProgressBar

android:id="@+id/progress_bar1"

style="@android:style/Widget.ProgressBar.Inverse"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="50"

android:background="#ff00ff"

android:paddingTop="4dp" />

通过android:backgroup设置了背景色

阅读全文

与android好看进度条相关的资料

热点内容
文件夹横向排列的竖向排列 浏览:449
51单片机驱动摄像头模块 浏览:687
政府文件加密没法转换 浏览:370
android判断栈顶 浏览:329
凭证软件源码 浏览:859
androidwebview滚动事件 浏览:9
如何将电脑上的图片压缩成文件包 浏览:899
程序员转金融IT 浏览:834
黑马程序员培训效果如何 浏览:911
本地集成编译 浏览:528
韩国电影哪个app可以看 浏览:703
玖月授权什么app什么梗 浏览:785
怎么使用服务器上的ip地址是什么情况 浏览:750
手机密码加密后怎么解密 浏览:343
华为云的服务器的ip地址怎么访问不 浏览:367
webstormvue在线实时编译生效 浏览:184
3225pdf 浏览:171
java中的常用类 浏览:395
安卓手机oppo反向色调怎么开 浏览:138
罗志祥pdf 浏览:224