自定义进度条的Android? [英] Custom Progress Bar in Android?
问题描述
我还没有得到一个线索,如何做到这一点。我的进度条应该是云的形状。可有人告诉我去一本书,补习或只给了正确的一步一步的方法是什么?
I havent got a clue to how to do this. My progress bar should be the shape of cloud. Can someone direct me to a book, tutorial or just give the right step by step method?
感谢您的时间。
推荐答案
如图所示的此处您可以使用图像的观点得到这样的效果的自定义滚动条。
As shown here you can use image views to get custom scroll bar like effect.
布局XML在这个例子中自定义进度条是:
The layout XML for custom progress bar in that example is:
<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>
然后,他创建的类文件图像作为列表:
And then he creates a list of images in class file as:
/**
* 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)
终于在处理程序,他做的工作休息图片:
Then he starts a Thread that sleeps for 0.3 seconds and calls the handler with handler.sendEmptyMessage(0);
and finally in Handler he do the rest of the work of images:
@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);
}
另外看看 rel="nofollow">和的这里。
Also take a look at here and here.
这篇关于自定义进度条的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!