<分区>
我还不知道如何做到这一点。我的进度条应该是云的形状。有人可以指导我阅读书籍、教程或只是给出正确的分步方法吗?
感谢您的宝贵时间。
<分区>
我还不知道如何做到这一点。我的进度条应该是云的形状。有人可以指导我阅读书籍、教程或只是给出正确的分步方法吗?
感谢您的宝贵时间。
最佳答案
如图here您可以使用 ImageView 来获得类似效果的自定义滚动条。
该示例中自定义进度条的布局 XML 是:
<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>
然后他在类文件中创建了一个图像列表:
/**
* 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");
}
然后他启动一个 hibernate 0.3 秒的线程并使用 handler.sendEmptyMessage(0);
调用处理程序,最后在处理程序中他完成图像的其余工作:
@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);
}
关于java - Android 中的自定义进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4581812/