Android中的自定义进度栏?

Android中的自定义进度栏?,第1张

Android中的自定义进度栏?

如此处所示,您可以使用图像视图来获得自定义滚动条效果。

在该示例中,自定义进度栏的布局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>

然后他在类文件中创建图像列表,如下所示:

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);
最后在Handler中,完成图像的其余工作:

@Overridepublic 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);}

也可以在这里和这里看看。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5176849.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-18
下一篇2022-11-18

发表评论

登录后才能评论

评论列表(0条)

    保存