android 自定义水平和圆形progressbar 只定义一些style就可以

效果图:

修改progressbar 让他满足自己的需求一般来说只修改一下,progressbar的style就可以满足需求了:

activity代码:仅仅显示一个布局而已

package com.example.testcustomprogressbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
}

xml界面:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.testcustomprogressbar.MainActivity" >

    <ProgressBar
        android:id="@+id/my_customprogressbar1"
        style="@style/mycustom_progressbar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <ProgressBar
        android:id="@+id/my_customprogressbar2"
        style="@style/mycustom_progressbar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/my_customprogressbar1"
        android:layout_below="@+id/my_customprogressbar1"
        android:layout_marginTop="26dp" />

    <ProgressBar
        android:id="@+id/my_customprogressbar3"
        style="@style/mycustom_progressbar3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/my_customprogressbar2"
        android:layout_below="@+id/my_customprogressbar2"
        android:layout_marginTop="26dp" />

     <ProgressBar
        android:id="@+id/my_customprogressbar4"
        style="@style/mycustom_progressbar_hor"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/my_customprogressbar3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="22dp"
        android:max="100"
        android:progress="40"
        android:secondaryProgress="60" />

    <ProgressBar
        android:id="@+id/my_customprogressbar5"
        style="@style/mycustom_progressbar_hor2"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/my_customprogressbar4"
        android:layout_below="@+id/my_customprogressbar4"
        android:layout_marginTop="26dp"
        android:max="100"
        android:progress="40"
        android:secondaryProgress="60" />

</RelativeLayout>

第一种圆形progressbar 仅仅让一个图片旋转起来:

style的代码:

 <style name="mycustom_progressbar1">
        <item name="android:indeterminateDrawable">@drawable/progressbar_ver_image</item>
        <item name="android:minHeight">30dp</item>
        <item name="android:minWidth">30dp</item>
        <item name="android:maxHeight">60dp</item>
        <item name="android:maxWidth">60dp</item>
    </style>

progressbar_ver_image的代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- 定义一个旋转的动画 ,图片是我们自定义的-->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/resizeapi"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

</rotate>

第二种圆形progressbar 使用一个动画:

style:

 <style name="mycustom_progressbar2">
        <item name="android:indeterminateDrawable">@drawable/progressbar_ver_animation</item>
        <item name="android:minHeight">60dp</item>
        <item name="android:minWidth">60dp</item>
        <item name="android:maxHeight">100dp</item>
        <item name="android:maxWidth">100dp</item>
    </style>

progressbar_ver_animation的代码:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:drawable="@drawable/ok1"
        android:duration="250"/>
    <item
        android:drawable="@drawable/ok2"
        android:duration="250"/>
    <item
        android:drawable="@drawable/ok3"
        android:duration="250"/>
    <item
        android:drawable="@drawable/ok4"
        android:duration="250"/>

</animation-list>

第三种圆形progressbar 使用shape来构建drawable:

<style name="mycustom_progressbar3">
        <item name="android:indeterminateDrawable">@drawable/progressbar_ver_shape</item>
        <item name="android:minHeight">60dp</item>
        <item name="android:minWidth">60dp</item>
        <item name="android:maxHeight">100dp</item>
        <item name="android:maxWidth">100dp</item>
    </style>

progressbar_ver_shape的代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- 定义一个旋转的动画 ,图片是我们自定义的shape -->
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >
    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >
        <gradient
            android:centerColor="#FFFFFF"
            android:centerY="0.50"
            android:endColor="#1E90FF"
            android:startColor="#000000"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

第四种: 横向progressbar 复制粘贴系统的style,然后修改:

<?xml version="1.0" encoding="utf-8"?>

<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="#ffff0000"
                    android:centerColor="#ffff0000"
                    android:centerY="0.75"
                    android:endColor="#ffff0000"
                    android:angle="270"
            />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#800000ff"
                        android:centerColor="#800000ff"
                        android:centerY="0.75"
                        android:endColor="#800000ff"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress"
        >
        <clip >

            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#ff00ff00"
                        android:centerColor="#ff00ff00"
                        android:centerY="0.75"
                        android:endColor="#ff00ff00"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>

</layer-list>

这样直接在progressbar中引用该style就可以满足需求了,当然我们也可以把progressbar background progress secondprogress都分别定义成一个drawable,然后使用:

background:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="5dip" />
    <gradient
        android:angle="270"
        android:centerColor="#ffff0000"
        android:centerY="0.75"
        android:endColor="#ffff0000"
        android:startColor="#ffff0000" />
</shape>

progress:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="5dip" />

    <gradient
        android:angle="270"
        android:centerColor="#ff00ff00"
        android:centerY="0.75"
        android:endColor="#ff00ff00"
        android:startColor="#ff00ff00" />

</shape>

secondprogress:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="5dip" />

    <gradient
        android:angle="270"
        android:centerColor="#800000ff"
        android:centerY="0.75"
        android:endColor="#800000ff"
        android:startColor="#800000ff" />

</shape>

这个时候style中的代码就会清晰一点:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/progressbar_hor_bg">
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip android:drawable="@drawable/progressbar_hor_second_progress" >
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip android:drawable="@drawable/progressbar_hor_progress" >
        </clip>
    </item>

    <!-- progress 这个地方原作者写的是一个点9的图-->
    <!-- <item android:id="@android:id/progress">
        <clip>
            <nine-patch android:src="@drawable/progress_patch_galy" />
        </clip>
    </item>   -->
</layer-list>

嘿嘿..最后,做人要厚道:神一般男人的原博主博文连接http://blog.csdn.net/mad1989/article/details/38042875

对了,代码还是贴上来吧.总感觉在ide中直接看代码会更舒服一些:http://download.csdn.net/detail/u010399316/9000197

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-09 00:07:21

android 自定义水平和圆形progressbar 只定义一些style就可以的相关文章

android 自己定义水平和圆形progressbar 仅仅定义一些style就能够

效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" > 改动progressbar 让他满足自己的需求一般来说仅仅改动一下,progressbar的style就能够满足需求了: activity代码:只显示一个布局而已 package com.example.testcustomprogre

android自定义view-打造圆形ImageView(四)终结篇

前言: 说实话,这段时间忙着修改毕业论文,好长时间没有碰代码了,真是罪过呀.今天我们就来奉上我们打造圆形ImageView的终结篇,以后如果还有新的创意再说啦.本文是在前面三篇的基础上得来的,详细请戳android自定义view-打造圆形ImageView(一).android自定义view-打造圆形ImageView(二).android自定义view-打造圆形ImageView(三). 效果图: 正文: 其实看了上面的效果图,大家应该都一目了然了,就是很多应用经常见到的带有白色边缘的渐变头像

自定义各式各样的圆形ProgressBar

     上面三个图分别是 开始时的样子,走进度时候的样子,最后完成的样子 自定义各式各样的圆形ProgressBar

Android 自定义漂亮的圆形进度条

这几天对Android中实现画圆弧及圆弧效果中所实现的效果进行了修改,改为进度圆心进度条,效果如图所示 TasksCompletedView.java 代码如下 import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; impo

android自定义View绘制圆形头像与椭圆头像

要实现这两种效果,需要自定义View,并且有两种实现方式. 第一种: public class BitmapShaders extends View { private  BitmapShader bitmapShader = null; private Bitmap bitmap = null; private Paint paint = null; private ShapeDrawable shapeDrawable = null; private int BitmapWidth  = 0

Android自定义类似ProgressDialog效果的Dialog

Android自定义类似ProgressDialog效果的Dialog. 方法如下: 1.首先准备两张自己要定义成哪样子的效果的图片和背景图片(也可以不要背景). 如我要的效果: 2.定义loading_dialog.xml布局文件(这里你也可以按自己的布局效果定义,关键是要有个imageView): [html] view plaincopy <?xml version="1.0" encoding="utf-8"?> <LinearLayout

Android自定义进度条-带文本(文字进度)的水平进度条(ProgressBar)

/** * 带文本提示的进度条 */ public class TextProgressBar extends ProgressBar { private String text; private Paint mPaint; public TextProgressBar(Context context) { super(context); initText(); } public TextProgressBar(Context context, AttributeSet attrs, int d

Android自定义View——圆形进度条式按钮

介绍 今天上班的时候有个哥们问我怎么去实现一个按钮式的进度条,先来看看他需要实现的效果图. 和普通的圆形进度条类似,只是中间的地方有两个状态表示,未开始,暂停状态.而且他说圆形进度的功能已经实现了.那么我们只需要对中间的两个状态做处理就行了. 先来看看实现的效果图: 上面说了我们只需要处理中间状态的变化就可以了,对于进度的处理直接使用了弘洋文章中实现: http://blog.csdn.net/lmj623565791/article/details/43371299 下面开始具体实现. 具体实

android自定义View之(六)------高仿华为荣耀3C的圆形刻度比例图(ShowPercentView)

为什么写这篇文章: 显示当前的容量所占的比例,表现当前计划的进度,一般都会采用百分比的方式,而图形显示,以其一目了然的直观性和赏心悦目的美观形成为了我们的当然的首选. 在图形表示百分比的方法中,我们有用画圆的圆形进度条的方法<<android自定义View之(二)------简单进度条显示样例篇>>,也有用画弧形的进度条的方法<<android自定义View之(三)------视频音量调控样例>>,今天看到华为荣耀3C的一个界面: 个人觉得这个表示比例的圆形