Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android中的自定义进度条?_Java_Android_Xml_Progress Bar_Progress - Fatal编程技术网

Java Android中的自定义进度条?

Java Android中的自定义进度条?,java,android,xml,progress-bar,progress,Java,Android,Xml,Progress Bar,Progress,我一点儿也不知道怎么做。我的进度条应该是云的形状。有人能告诉我一本书,一个教程,或者只是给出正确的一步一步的方法吗 谢谢您的时间。如图所示,您可以使用图像视图获得自定义滚动条效果 该示例中自定义进度条的布局XML为: <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/re

我一点儿也不知道怎么做。我的进度条应该是云的形状。有人能告诉我一本书,一个教程,或者只是给出正确的一步一步的方法吗

谢谢您的时间。

如图所示,您可以使用图像视图获得自定义滚动条效果

该示例中自定义进度条的布局XML为:

<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center" android:layout_height="wrap_content"
    android:paddingLeft="30sp" android:paddingRight="30sp">
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/progress_1"
        android:id="@+id/imgOne" android:tag="1"></ImageView>
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/progress_2"
        android:id="@+id/imgTwo" android:layout_toRightOf="@id/imgOne"
        android:tag="2"></ImageView>
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/progress_3"
        android:id="@+id/imgThree" android:layout_toRightOf="@id/imgTwo"
        android:tag="3"></ImageView>
    <TextView android:id="@+id/TextView01" android:layout_height="wrap_content"
        android:layout_toRightOf="@id/imgThree" android:layout_width="wrap_content"
        android:layout_alignTop="@id/imgThree" android:layout_alignBottom="@id/imgThree"
        android:gravity="bottom" android:text="Please Wait..."></TextView>
</RelativeLayout>

也看一看./P>> P>我最后用Harry Joy推荐的一个基础来挖掘。但是,如果您想要与android SDK版本相同的功能,我必须对ProgressBar类中的这些功能进行一些更改。我所做的更改使中间绘图可以定义和设置动画

确保按照说明操作,但将RoundProgress类替换为:

public class RoundProgress extends RelativeLayout {
private ImageView progressDrawableImageView;
private ImageView trackDrawableImageView;
private ImageView backGroundImageView;
private double max = 100;
private AttributeSet attrs2 ;
private Transformation mTransformation;
private AlphaAnimation mAnimation;
private int mBehavior;
private int mDuration;
private Interpolator mInterpolator;
private static Context ctx;
private int bgResource;

public int getMax() {
    Double d = new Double(max);
    return d.intValue();
}

public double getMaxDouble() {
    return max;
}

public void setMax(int max) {
    Integer maxInt = new Integer(max);
    maxInt.doubleValue();
    this.max = max;
}

public void setMax(double max) {
    this.max = max;
}

public RoundProgress(Context context, AttributeSet attrs) {
    super(context, attrs);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.round_progress, this);
    setup(context, attrs);
}

protected void setup(Context context, AttributeSet attrs)
{
    attrs2 = attrs;
    ctx = context;
    TypedArray a = context.obtainStyledAttributes(attrs,
        R.styleable.RoundProgress);
    //setBackgroundResource(R.drawable.custom_loading_bg);
    backGroundImageView = (ImageView) findViewById(R.id.background_image_view);
    backGroundImageView.setBackgroundResource(R.drawable.custom_loading_bg);


    final String xmlns="http://schemas.android.com/apk/res/com.digiphd.prospec";
   bgResource = attrs.getAttributeResourceValue(xmlns,
            "progressDrawable", 0);
    progressDrawableImageView = (ImageView) findViewById(
            R.id.progress_drawable_image_view);

    progressDrawableImageView.setBackgroundResource(bgResource);

    int trackResource = attrs.getAttributeResourceValue(xmlns, "track", 0);
    trackDrawableImageView = (ImageView) findViewById(R.id.track_image_view);
    trackDrawableImageView.setBackgroundResource(trackResource);

    int progress = attrs.getAttributeIntValue(xmlns, "progress", 0);
    setProgress(progress);
    int max = attrs.getAttributeIntValue(xmlns, "max", 100);
    setMax(max);

    int numTicks = attrs.getAttributeIntValue(xmlns, "numTicks", 0);

    a.recycle();

    ProgressBarOutline outline = new ProgressBarOutline(context);
    //addView(outline);


}

public void setProgress(Integer value)
{
    setProgress((double) value);
}

public void setProgress(double value) {
    ClipDrawable drawable = (ClipDrawable)
            progressDrawableImageView.getBackground();
    double percent = (double) value/ (double)max;
    int level = (int)Math.floor(percent*10000);

    drawable.setLevel(level);
}

public void setIntermediate(boolean t)
{
   if(t){
       progressDrawableImageView.setBackgroundResource(R.drawable.custom_intermediate_bg);
       startAnimation();
   }else{
       progressDrawableImageView.clearAnimation();
       progressDrawableImageView.setBackgroundResource(bgResource);

   }
}

/**
 * <p>Start the indeterminate progress animation.</p>
 */
void startAnimation() {
    int visibility = getVisibility();
    if (visibility != VISIBLE) {
        return;
    }
    Log.d("INTERMEDIATE","ANIMATION START!");
    mDuration = 1000;

        if (mInterpolator == null) {
            mInterpolator = new LinearInterpolator();
        }

        mTransformation = new Transformation();
        mAnimation = new AlphaAnimation(0.0f, 1.0f);
        mAnimation.setRepeatMode(Animation.REVERSE);
        mAnimation.setRepeatCount(Animation.INFINITE);
        mAnimation.setDuration(mDuration);
        mAnimation.setInterpolator(mInterpolator);
        mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
        progressDrawableImageView.startAnimation(mAnimation);


}
}
public类RoundProgress扩展了RelativeLayout{
私有ImageView progressDrawableImageView;
私有ImageView trackDrawableImageView;
私有ImageView背景ImageView;
私人双最大值=100;
私有属性集属性2;
私有化改造;
私人字母动画制作;
私人行为;
私人投资;
专用内插器;
私有静态上下文ctx;
私有资源;
公共int getMax(){
双d=新双d(最大值);
返回d.intValue();
}
公共双精度getMaxDouble(){
返回最大值;
}
公共void setMax(int max){
整数maxInt=新整数(最大值);
maxInt.doubleValue();
this.max=max;
}
公共无效设置最大值(双倍最大值){
this.max=max;
}
公共RoundProgress(上下文、属性集属性){
超级(上下文,attrs);
LayoutFlater充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
充气机。充气(右布局。圆形进度,本);
设置(上下文、属性);
}
受保护的无效设置(上下文、属性集属性)
{
attrs2=attrs;
ctx=上下文;
TypedArray a=上下文。获取样式属性(属性,
R.styleable.RoundProgress);
//setBackgroundResource(R.drawable.custom_loading_bg);
backGroundImageView=(ImageView)findViewById(R.id.background\u image\u view);
backGroundImageView.setBackgroundResource(R.drawable.custom_loading_bg);
最终字符串xmlns=”http://schemas.android.com/apk/res/com.digiphd.prospec";
bgResource=attrs.getAttributeResourceValue(xmlns,
“可进行绘制”,0);
progressDrawableImageView=(ImageView)findViewById(
R.id.进度(可绘制图像视图);
progressDrawableImageView.setBackgroundResource(bgResource);
int trackResource=attrs.getAttributeResourceValue(xmlns,“track”,0);
trackDrawableImageView=(ImageView)findViewById(R.id.track\u image\u view);
trackDrawableImageView.setBackgroundResource(trackResource);
int progress=attrs.getAttributeIntValue(xmlns,“progress”,0);
设定进度(进度);
int max=attrs.getAttributeIntValue(xmlns,“max”,100);
setMax(max);
int numTicks=attrs.getAttributeIntValue(xmlns,“numTicks”,0);
a、 回收();
ProgressBarOutline轮廓=新的ProgressBarOutline(上下文);
//addView(大纲);
}
public void setProgress(整数值)
{
设置进度((双)值);
}
public void setProgress(双值){
ClipDrawable drawable=(ClipDrawable)
progressDrawableImageView.getBackground();
双百分比=(双)值/(双)最大值;
整数级=(整数)数学下限(百分比*10000);
可拉深。设置标高(标高);
}
公共void setIntermediate(布尔值t)
{
if(t){
progressDrawableImageView.setBackgroundResource(R.drawable.custom_intermediate_bg);
startAnimation();
}否则{
progressDrawableImageView.clearAnimation();
progressDrawableImageView.setBackgroundResource(bgResource);
}
}
/**
*启动不确定进度动画

*/ void startAnimation(){ int visibility=getVisibility(); 如果(可见性!=可见){ 返回; } Log.d(“中间”,“动画开始!”); 持续时间=1000; if(mInterpolator==null){ mInterpolator=新的LinearInterpolator(); } MTTransformation=新转换(); mAnimation=新字母动画(0.0f,1.0f); mAnimation.setRepeatMode(动画.反转); mAnimation.setRepeatCount(Animation.INFINITE); 设置持续时间(m持续时间); 设置插值器(最小插值器); mAnimation.setStartTime(动画。在第一帧上启动); progressDrawableImageView.startAnimation(mAnimation); } }

现在,在您的活动中,您可以在需要时调用.setIntermediate(true或false)。

您让我开心了。正是我需要的。
@Override
public void handleMessage(Message msg) {
    int currentImage = 0;
    int nextImage = 0;
    // Logic to change the images
    for (ImageView imageView : imageHolders) {
        currentImage = Integer.parseInt(imageView.getTag().toString());
        if (currentImage < 9) {
            nextImage = currentImage + 1;
        } else {
            nextImage = 1;
        }
        imageView.setTag("" + nextImage);
        imageView.setImageResource(getResources().getIdentifier(
                images.get(nextImage - 1), "drawable",
                "com.beanie.example"));
    }
    super.handleMessage(msg);
}
public class RoundProgress extends RelativeLayout {
private ImageView progressDrawableImageView;
private ImageView trackDrawableImageView;
private ImageView backGroundImageView;
private double max = 100;
private AttributeSet attrs2 ;
private Transformation mTransformation;
private AlphaAnimation mAnimation;
private int mBehavior;
private int mDuration;
private Interpolator mInterpolator;
private static Context ctx;
private int bgResource;

public int getMax() {
    Double d = new Double(max);
    return d.intValue();
}

public double getMaxDouble() {
    return max;
}

public void setMax(int max) {
    Integer maxInt = new Integer(max);
    maxInt.doubleValue();
    this.max = max;
}

public void setMax(double max) {
    this.max = max;
}

public RoundProgress(Context context, AttributeSet attrs) {
    super(context, attrs);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.round_progress, this);
    setup(context, attrs);
}

protected void setup(Context context, AttributeSet attrs)
{
    attrs2 = attrs;
    ctx = context;
    TypedArray a = context.obtainStyledAttributes(attrs,
        R.styleable.RoundProgress);
    //setBackgroundResource(R.drawable.custom_loading_bg);
    backGroundImageView = (ImageView) findViewById(R.id.background_image_view);
    backGroundImageView.setBackgroundResource(R.drawable.custom_loading_bg);


    final String xmlns="http://schemas.android.com/apk/res/com.digiphd.prospec";
   bgResource = attrs.getAttributeResourceValue(xmlns,
            "progressDrawable", 0);
    progressDrawableImageView = (ImageView) findViewById(
            R.id.progress_drawable_image_view);

    progressDrawableImageView.setBackgroundResource(bgResource);

    int trackResource = attrs.getAttributeResourceValue(xmlns, "track", 0);
    trackDrawableImageView = (ImageView) findViewById(R.id.track_image_view);
    trackDrawableImageView.setBackgroundResource(trackResource);

    int progress = attrs.getAttributeIntValue(xmlns, "progress", 0);
    setProgress(progress);
    int max = attrs.getAttributeIntValue(xmlns, "max", 100);
    setMax(max);

    int numTicks = attrs.getAttributeIntValue(xmlns, "numTicks", 0);

    a.recycle();

    ProgressBarOutline outline = new ProgressBarOutline(context);
    //addView(outline);


}

public void setProgress(Integer value)
{
    setProgress((double) value);
}

public void setProgress(double value) {
    ClipDrawable drawable = (ClipDrawable)
            progressDrawableImageView.getBackground();
    double percent = (double) value/ (double)max;
    int level = (int)Math.floor(percent*10000);

    drawable.setLevel(level);
}

public void setIntermediate(boolean t)
{
   if(t){
       progressDrawableImageView.setBackgroundResource(R.drawable.custom_intermediate_bg);
       startAnimation();
   }else{
       progressDrawableImageView.clearAnimation();
       progressDrawableImageView.setBackgroundResource(bgResource);

   }
}

/**
 * <p>Start the indeterminate progress animation.</p>
 */
void startAnimation() {
    int visibility = getVisibility();
    if (visibility != VISIBLE) {
        return;
    }
    Log.d("INTERMEDIATE","ANIMATION START!");
    mDuration = 1000;

        if (mInterpolator == null) {
            mInterpolator = new LinearInterpolator();
        }

        mTransformation = new Transformation();
        mAnimation = new AlphaAnimation(0.0f, 1.0f);
        mAnimation.setRepeatMode(Animation.REVERSE);
        mAnimation.setRepeatCount(Animation.INFINITE);
        mAnimation.setDuration(mDuration);
        mAnimation.setInterpolator(mInterpolator);
        mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
        progressDrawableImageView.startAnimation(mAnimation);


}
}