将刷新 ImageView 变成 ProgressBar

发布于 2024-09-02 04:12:15 字数 816 浏览 2 评论 0原文

我正在为我的 Android 应用程序做一个自定义标题,我想要一个像 Twitter 应用程序一样的刷新按钮。 我正在使用 RelativeLayout ,我的 ImageView 是这样定义的:

<ImageView android:id="@+id/title_refresh"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_menu_refresh"
    android:layout_alignParentRight="true">
</ImageView>

在我的 Activity 中,我有这样的东西:

refreshView = (ImageView) findViewById(R.id.title_refresh);
refreshView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        /* Make the refreshView turn into a progress bar. */
        startService(new Intent(MyActivity.this, MyService.class));
    }
}

我希望 ImageView 在我等待时变成 ProgressBar服务完成处理。 正确的方法是如何做到这一点?

I am doing a custom title for my android app and I want to have a refresh button like the Twitter app.
I am using a RelativeLayout an my ImageView is defined by:

<ImageView android:id="@+id/title_refresh"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_menu_refresh"
    android:layout_alignParentRight="true">
</ImageView>

In my Activity I have something like this:

refreshView = (ImageView) findViewById(R.id.title_refresh);
refreshView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        /* Make the refreshView turn into a progress bar. */
        startService(new Intent(MyActivity.this, MyService.class));
    }
}

I would like the ImageView to turn into a ProgressBar while I wait for my service to finish processing.
How is the correct way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城之時有危險 2024-09-09 04:12:15

您可以将进度条视图添加到 RelativeLayout 中,该视图与 ImageViewvisibility:gone 重叠,然后使用 setVisibilty(View. VISIBILE)/setVisibilty(View.GONE) 在您的 ImageViewProgressBar 上。

也许 ViewSwitcher 也可以帮助您。

You could add the progress bar view into the RelativeLayout which overlaps the ImageView with visibility:gone and then play with setVisibilty(View.VISIBILE)/setVisibilty(View.GONE) on your ImageView and ProgressBar.

Maybe a ViewSwitcher could help you too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文