定位后面的按钮,一个进度条 [英] Positioning a progress bar behind a button

查看:156
本文介绍了定位后面的按钮,一个进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮这是一个定义 RelativeLayout的如下:

I have a Button that is defined in a RelativeLayout as follows:

<Button
        android:id="@+id/search_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/current_location"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:paddingBottom="30dp"
        android:paddingTop="30dp"
        android:text="@string/search" />

我想补充一个进度占据完全相同的空间按钮,这样,当按钮被禁用(半透明),你可以看到它背后的进度条后面的按钮。我将如何做到这一点?

I would like to add a ProgressBar behind the Button that occupies the exact same space as the Button, so that when the button is disabled (translucent), you can see the progress bar behind it. How would I do this?

推荐答案

要做到这一点,我不得不在定义按钮,我的的main.xml 第一,其次是进步酒吧如下:

To do this I had to define the button in my main.xml first, followed by the progress bar as follows:

<Button
    android:id="@+id/search_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/current_location"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:paddingBottom="30dp"
    android:paddingTop="30dp"
    android:text="@string/search" />

<ProgressBar
    android:id="@+id/cooldown_bar"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/search_button"
    android:layout_below="@id/current_location"
    android:layout_marginBottom="6dp"
    android:layout_marginLeft="9dp"
    android:layout_marginRight="9dp"
    android:layout_marginTop="1dp"
    android:indeterminate="false"
    android:progressDrawable="@drawable/progress_bar" />

那么,一旦我已经初始化所有的GUI组件,我只好把按钮早在进度条的前面加上:

Then, once I had initialized all the GUI components, I had to bring the button back in front of the progress bar with:

searchButton.bringToFront();

的最终结果

按钮启用时:

The end result

Button when enabled:

按钮与进度条时禁用:

这篇关于定位后面的按钮,一个进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆