2016-04-18 15 views
0

Wie erstelle ich eine benutzerdefinierte Fortschrittsleiste in Android, die für die Fortschritts- und Hintergrundelemente eine Zeichenfläche hat? dies ist eine meiner QuelleBenutzerdefinierte ProgressBar in Android mit Bild

<style parent="@android:style/Widget.ProgressBar" name="customProgressBar"> 
    <item name="android:indeterminateDrawable">@drawable/ic_refresh_white</item> 
</style> 



<ProgressBar 
      android:id="@+id/pdWithImage" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      style="@style/customProgressBar" 
      android:layout_centerInParent="true" /> 

i hinzugefügt Bild Hintergrund png, aber wenn ich meine app progresbar laufen nicht dreht , wie ich mein Problem lösen kann?

Antwort

0
class ProgressDialog extends Dialog { 

     private ImageView iv; 

     public ProgressDialog(Context context, int resourceIdOfImage) { 
      super(context, R.style.YourStyle); 
      WindowManager.LayoutParams wlmp = getWindow().getAttributes(); 
      wlmp.gravity = Gravity.CENTER_HORIZONTAL; 
      getWindow().setAttributes(wlmp); 
      setTitle(null); 
      setCancelable(false); 
      setOnCancelListener(null); 
      LinearLayout layout = new LinearLayout(context); 
      layout.setOrientation(LinearLayout.VERTICAL); 
      LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
      iv = new ImageView(context); 
      iv.setImageResource(resourceIdOfImage); 
      layout.addView(iv, params); 
      addContentView(layout, params); 
     } 

     @Override 
     public void show() { 
      super.show(); 
      RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f); 
      anim.setInterpolator(new LinearInterpolator()); 
      anim.setRepeatCount(Animation.INFINITE); 
      anim.setDuration(3000); 
      iv.setAnimation(anim); 
      iv.startAnimation(anim); 
     } 
    } 

Und nennen diese ProgressDialog Methode mit Bild wie dieses

ProgressDialog(activity, R.drawable.image) 

hoffe, es hilft Ihnen :)

+0

ich habe progessbar nicht progressDialog @Ashwini Bhat – BekaKK

+0

http://stackoverflow.com/questions/2819778/custom-drawable-for-progressbar-progressdialog Überprüfen Sie diesen Link –

+0

überprüfen Sie diese http://stackoverflow.com/questions/35220756/style-for-android-progressdialog/35221468#35221468 –

Verwandte Themen