2014-11-28 4 views
0

Как создать пользовательскую панель прогресса на Android, которая может быть доступна для продвижения и фоновых элементов?Пользовательский ProgressBar в Android с помощью PNG

Все примеры, которые я видел, были градиенты, как это:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- Define the background properties like color etc --> 
    <item android:id="@android:id/background"> 
     <shape> 
      <gradient 
        android:startColor="#000001" 
        android:centerColor="#0b131e" 
        android:centerY="1.0" 
        android:endColor="#0d1522" 
        android:angle="270" 
      /> 
     </shape> 
    </item> 

<!-- Define the progress properties like start color, end color etc --> 
    <item android:id="@android:id/progress"> 
     <clip> 
      <shape> 
       <gradient 
        android:startColor="#007A00" 
        android:centerColor="#007A00" 
        android:centerY="1.0" 
        android:endColor="#06101d" 
        android:angle="270" 
       /> 
      </shape> 
     </clip> 
    </item> 

</layer-list> 

Вместо градиента, я хочу использовать изображение, PNG или вытяжке.

+1

Учитывая, что 'ProgressBar' может быть любым произвольного размера в пикселях (в зависимости от размера экрана и плотности), используя«образ, PNG или растяжимые»не может дать вам качественные результаты , При этом попробуйте '' вместо ''. – CommonsWare

+0

Попробуйте это. http://www.techrepublic.com/blog/software-engineer/create-a-transparent-progress-dialog-on-android/ – Sridhar

ответ

0

Вы можете сделать это как то

 ProgressDialog pd = ProgressDialog.show(HomeActivity.this, null, null, true, false); 

     pd.setContentView(R.layout.progressdialog); 

     ProgressBar bar = (ProgressBar) pd.findViewById(R.id.pdWithImage); 
     Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.default_profile_image); 
     Drawable d = new BitmapDrawable(getResources(),b); 

     bar.setBackgroundDrawable(d); 

и это обычай прогрессбар макет

progressdialog

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:background="@android:color/transparent" > 

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

</RelativeLayout> 
0

Во-первых, добавьте progressbar_progress_clip.xml:

<?xml version="1.0" encoding="utf-8"?> 
<clip 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/progressbar_progressing" 
    android:clipOrientation="horizontal" 
    android:gravity="left"/> 

Затем добавьте индикатор выполнения и два изображения в относительный макет, чтобы изображения можно было рисовать после строки состояния. Что-то вроде этого:

<RelativeLayout 
       android:id="@+id/relativeLayout1" 
       android:layout_width="0dip" 
       android:layout_height="fill_parent" 
       android:layout_marginLeft="10dip" 
       android:layout_marginRight="10dip" 
       android:layout_weight="94" > 

       <ProgressBar 
        android:id="@+id/pBarOverallStatus" 
        style="?android:attr/progressBarStyleHorizontal" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginBottom="2dp" 
        android:layout_marginTop="2dp" 
        android:indeterminateOnly="false" 
        android:max="100" 
        android:progressDrawable="@drawable/progressbar_progress_clip" > 
       </ProgressBar> 

       <ImageView 
        android:id="@+id/ringLeft" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:layout_alignParentLeft="true" 
        android:layout_centerVertical="true" 
        android:layout_marginLeft="7dp" 
        android:contentDescription="@string/status_bar_ring" 
        android:src="@drawable/status_bar_ring" /> 

       <ImageView 
        android:id="@+id/ringRight" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:layout_alignParentRight="true" 
        android:layout_centerVertical="true" 
        android:layout_marginRight="7dp" 
        android:contentDescription="@string/status_bar_ring" 
        android:src="@drawable/status_bar_ring" /> 
      </RelativeLayout> 
Смежные вопросы