web-dev-qa-db-fra.com

Cercle de rotation ProgressDialog

Je veux implémenter ProgressDialog comme celui-ci, sans frame supplémentaire .: Pic

Mais je suis celui-ci. Comment pourrais-je changer cela?

enter image description here

Voici mon code pour ProgressDialog. Merci d'avance

private ProgressDialog mProgressDialog;
   ............
   mProgressDialog = new ProgressDialog(activity);
   mProgressDialog.setIndeterminate(false);
   mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
   ............
    public class ProgressTask extends AsyncTask <Fragment,Void,Fragment>{
            @Override
            protected void onPreExecute(){
                mProgressDialog.show();
            }

            @Override
            protected Fragment doInBackground(Fragment... arg0) {   
                    //my stuff is here
            }

            @Override
            protected void onPostExecute(Fragment result) {
                   mProgressDialog.dismiss();
            }
        }
55
Andrew Rahimov

Il suffit de passer de ProgressDialog à ProgressBar dans une présentation:

res/layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:id="@+id/container">

    <LinearLayout
        Android:layout_width="match_parent"
        Android:layout_height="match_parent" >
        //Your content here
     </LinearLayout>

        <ProgressBar
            Android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:layout_centerHorizontal="true"
            Android:layout_centerVertical="true"
            Android:visibility="gone"
            Android:indeterminateDrawable="@drawable/progress" >
        </ProgressBar>
</RelativeLayout>

src/yourPackage/YourActivity.Java

public class YourActivity extends Activity{

private ProgressBar bar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);
    bar = (ProgressBar) this.findViewById(R.id.progressBar);
    new ProgressTask().execute();
}
private class ProgressTask extends AsyncTask <Void,Void,Void>{
    @Override
    protected void onPreExecute(){
        bar.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... arg0) {   
           //my stuff is here
    }

    @Override
    protected void onPostExecute(Void result) {
          bar.setVisibility(View.GONE);
    }
}
}

drawable/progress.xml Ceci est une ProgressBar personnalisée que j’utilise pour changer les couleurs par défaut.

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

<!-- 
    Duration = 1 means that one rotation will be done in 1 second. leave it.
    If you want to speed up the rotation, increase duration value. 
    in example 1080 shows three times faster revolution. 
    make the value multiply of 360, or the ring animates clunky 
-->
<rotate xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:fromDegrees="0"
    Android:pivotX="50%"
    Android:pivotY="50%"
    Android:duration="1"
    Android:toDegrees="360" >

    <shape
        Android:innerRadiusRatio="3"
        Android:shape="ring"
        Android:thicknessRatio="8"
        Android:useLevel="false" >
        <size
            Android:height="48dip"
            Android:width="48dip" />

        <gradient
            Android:centerColor="@color/color_preloader_center"
            Android:centerY="0.50"
            Android:endColor="@color/color_preloader_end"
            Android:startColor="@color/color_preloader_start"
            Android:type="sweep"
            Android:useLevel="false" />
    </shape>

</rotate>
135
JackTurky

Mettez ce XML pour montrer seulement la roue:

<ProgressBar
    Android:indeterminate="true"
    Android:id="@+id/marker_progress"
    style="?android:attr/progressBarStyle"
    Android:layout_height="50dp" />
16
shym

J'utilisais View.INVISIBLE et View.VISIBLE et le ProgressBar clignotait lentement au lieu d'être constamment visible, basculé en View.GONE et View.VISIBLE et il fonctionne parfaitement

2
jp093121