【问题标题】:How to bring a Progress Bar in front of a Button in older API versions?如何在旧 API 版本中将进度条放在按钮前面?
【发布时间】:2017-01-19 18:32:41
【问题描述】:

我阅读了两篇关于这个主题的文章,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>

这是一个屏幕截图

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

编辑:

没有什么对我有用,所以我只会在需要显示进度条时隐藏按钮。

感谢您的帮助。

【问题讨论】:

标签: java android xml android-button android-progressbar


【解决方案1】:

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

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

【讨论】:

  • 我把它移到了布局的底部
  • 并添加了 bringToFront 方法但仍然不起作用
  • 清理并重建您的项目
  • 我会尝试清理和重建
【解决方案2】:

这里的解决方案,我只是改变我的元素的顺序

<?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" />
<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" 
    android:background=""/>



</RelativeLayout>

我为进度添加了背景,以查看进度在按钮前面

【讨论】:

  • 问题是如何在按钮前面显示进度条
  • 好的,你可以加入你需要的截图吗?
  • 这是一个屏幕截图
  • 好的,我更新答案告诉我这是否适合你
  • 更改顺序没有帮助
【解决方案3】:

在 ProgressBar 上设置高程; 2dp 似乎可以工作。

android:elevation="2dp"

您也可以尝试按照类似问题的已接受答案中的建议设置 translationZ。

我也遇到了这个答案作为替代。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-29
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多