java - 如何在较旧的 API 版本中将进度条放在按钮前面?

标签 java android xml android-button android-progressbar

我读了两篇关于这个主题的文章,thisthis .

但两者都提供了解决方案,例如更改海拔或平移。

问题是关于在不支持海拔或翻译属性的旧版本中在按钮前面添加进度条。

如何在 XML 和 Java 中执行此操作?!

或者无效。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.business.abdelhafiz.omar.civiltaif.LoginActivity">

    <ImageView
        android:src="@drawable/home_civil"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ProgressBar
        android:id="@+id/login_progressbar"
        android:layout_centerInParent="true"
        android:layout_width="@dimen/image_height"
        android:layout_height="@dimen/image_height" />

    <Button
        android:id="@+id/login_email"
        android:layout_centerInParent="true"
        android:text="@string/login_email"
        android:onClick="loginEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/login_anonymous"
        android:layout_centerInParent="true"
        android:layout_below="@id/login_email"
        android:text="@string/login_anonymous"
        android:onClick="loginAnonymous"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

这是截图

enter image description here

我想把进度条放在按钮前面

编辑:

对我来说没有任何效果,所以我会在需要显示进度条时隐藏按钮。

感谢您的帮助。

最佳答案

你可以像这样把它移到底部

<ImageView
    android:src="@drawable/home_civil"
    android:scaleType="fitXY"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<Button
    android:id="@+id/login_email"
    android:layout_centerInParent="true"
    android:text="@string/login_email"
    android:onClick="loginEmail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/login_anonymous"
    android:layout_centerInParent="true"
    android:layout_below="@id/login_email"
    android:text="@string/login_anonymous"
    android:onClick="loginAnonymous"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<ProgressBar
    android:id="@+id/login_progressbar"
    android:layout_centerInParent="true"
    android:layout_width="@dimen/image_height"
    android:layout_height="@dimen/image_height" />

或者在 onCreate 方法中只写 login_progressbar.bringToFront();

关于java - 如何在较旧的 API 版本中将进度条放在按钮前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41749192/

相关文章:

java - 无法在 Android 中创建 Amazon Sqs,但可以在 Java 应用程序中创建它

java - Android map : Failed to load map. 无法联系谷歌服务器

android - 在哪里放置不同大小的图标?

android - 动态添加的表在android中不显示

c# - 为 xml 反序列化自动创建的 C# 类不起作用

c# - 更改任何 svg 文件中所有元素的颜色

java - 分析 volatile 上下文中 JIT 生成的 x86 输出

java - 我的 Java Sieve 代码速度很慢并且无法按预期的时间复杂度进行扩展

android - DevicePolicyManager.resetPasswordWithToken 抛出 NPE

java - 使用 Jackson XmlMapper 序列化为 XML DOM