将进度条放置在按钮后面

2023-12-09

我有一个Button这是定义在RelativeLayout如下:

<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" />

我想在按钮后面添加一个进度条,它占据与按钮完全相同的空间,这样当按钮被禁用(半透明)时,您可以看到它后面的进度条。我该怎么做?


为此,我必须在我的main.xml首先是进度条,如下:

<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 组件,我就必须使用以下命令将按钮放回到进度条前面:

searchButton.bringToFront();

最终结果

按钮启用后:

Button when enabled

带进度条禁用时的按钮:

Button when disabled with progress bar

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将进度条放置在按钮后面 的相关文章

随机推荐