栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android中的自定义进度栏?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/449723.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号