Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As shown <a href="http://myandroidwidgets.googlecode.com/svn/trunk/Custom_Progress_Bar/" rel="nofollow">here</a> you can use image views to get custom scroll bar like effect.</p> <p>The layout XML for custom progress bar in that example is: </p> <pre><code>&lt;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"&gt; &lt;ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/progress_1" android:id="@+id/imgOne" android:tag="1"&gt;&lt;/ImageView&gt; &lt;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"&gt;&lt;/ImageView&gt; &lt;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"&gt;&lt;/ImageView&gt; &lt;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..."&gt;&lt;/TextView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And then he creates a list of images in class file as:</p> <pre><code>/** * 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&lt;ImageView&gt;(); 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&lt;String&gt;(); 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"); } </code></pre> <p>Then he starts a Thread that sleeps for 0.3 seconds and calls the handler with <code>handler.sendEmptyMessage(0);</code> and finally in Handler he do the rest of the work of images:</p> <pre><code>@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 &lt; 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); } </code></pre> <p>Also take a look at <a href="http://guides.wikinut.com/Progress-Bar-On-Android/4ws2d1y7/" rel="nofollow">here</a> and <a href="http://huuah.com/android-progress-bar-and-thread-updating/" rel="nofollow">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload