2011-01-03 4 views
6

나는 이것을 수행하는 방법에 대한 단서가 없다. 진행 바는 구름 모양이어야합니다. 누군가 나를 책이나 튜토리얼로 안내하거나 단계별 방법으로 올바른 단계를 줄 수 있습니까?Android의 맞춤 진행 표시 줄?

감사합니다.

답변

15

그림과 같이 here을 사용하면 이미지보기를 사용하여 효과처럼 사용자 정의 스크롤 막대를 얻을 수 있습니다.

<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> 

하고 그는 클래스 파일에서 이미지의 목록을 만듭니다 :

이 예에서는 사용자 정의 진행률 막대 레이아웃 XML입니다

/** 
* Loads the layout and sets the initial set of images 
*/ 
private void prepareLayout() { 
    LayoutInflater inflater = (LayoutInflater) context 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.myprogressbar, null); 
    addView(view); 

    imageHolders = new ArrayList<ImageView>(); 
    imageHolders.add((ImageView) view.findViewById(R.id.imgOne)); 
    imageHolders.add((ImageView) view.findViewById(R.id.imgTwo)); 
    imageHolders.add((ImageView) view.findViewById(R.id.imgThree)); 

    // Prepare an array list of images to be animated 
    images = new ArrayList<String>(); 

    images.add("progress_1"); 
    images.add("progress_2"); 
    images.add("progress_3"); 
    images.add("progress_4"); 
    images.add("progress_5"); 
    images.add("progress_6"); 
    images.add("progress_7"); 
    images.add("progress_8"); 
    images.add("progress_9"); 
} 

그런 다음 그는 잠들지 스레드를 시작합니다 0.3 초 ​​동안 핸들러를 호출하고 핸들러를 handler.sendEmptyMessage(0);으로 호출하고 마지막으로 Handler에서 나머지 이미지 작업을 수행합니다.

@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); 
} 

herehere도 확인하십시오.

+0

내 하루를 보냈습니다. 정확히 내가 필요로하는 것. – JehandadK

1

해리 조이 (Harry Joy)가 추천 한 광산의 기초로 Custom Progress Bar with Round Corners을 사용하여 마무리했습니다. 그러나 Android의 SDK 버전과 동일한 기능을 원한다면 ProgressBar 클래스의 intermediate이 있습니다. 일부 변경해야했습니다. 내가 변경 한 내용을 통해 중간 드로어 블을 정의하고 애니메이션으로 만들 수 있습니다.

당신이 지시 here을 준수합니다,하지만이 함께 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); 


} 
} 

을, 당신은 단지 .setIntermediate (true 또는 false)를 호출 할 수 있습니다.