Android 5.0-ProgressBar不能显示在按钮上 [英] Android 5.0 - ProgressBar cannot be displayed over a Button

查看:199
本文介绍了Android 5.0-ProgressBar不能显示在按钮上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为标题非常明确地表达了我的问题...所以这是我的布局:

I think the title is pretty explicit about my problem... So here is my layout :

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <Button
                    android:id="@+id/button_action"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Login" />

                <ProgressBar
                    android:id="@+id/progress_bar"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_centerInParent="true"/>

            </RelativeLayout>

在android SDK上< 21,没问题,ProgressBar正确显示在Button上方,并在Button中居中.但是在Android 5.0上,ProgressBar显示在按钮的后面.

On android SDKs < 21, no problem, the ProgressBar is correctly displayed over the Button and centered in the Button. But on Android 5.0, the ProgressBar is displayed behind the Button.

因此,当您在开发人员选项"设置中激活显示布局范围"选项时,可以看到它的位置正确,但是如果没有该选项,您将看不到屏幕上的任何内容.

So you can see it's correctly positionned it when you activate the option "Show layout bounds" in Developer Options settings, but you can't see anything on the screen without that option.

有人知道如何解决此问题吗?我想这是最近引入的海拔的问题,但我真的不知道该如何处理. 作为记录,我使用了来自support.v7的最新发布的Theme.AppCompat样式.

Would anybody know how to fix this? I guess it's a matter of elevation recently introduced, but I really don't know how to take care of it. For the record, I'm using the recently released Theme.AppCompat style from the support.v7.

我还尝试通过编程方式将setElevation(0)setTranslationY(0)应用于Button,但是它没有任何改变.所以我想知道它是否必须处理海拔高度.

I also tried to apply setElevation(0) and setTranslationY(0) to the Button programmatically but it didn't change anything. So I wonder if it has to deal with the elevation.

先谢谢大家

Mathieu

推荐答案

您可以将android:translationZ属性添加到ProgressBar:

<ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:translationZ="2dp"
    android:layout_centerInParent="true"/>

这篇关于Android 5.0-ProgressBar不能显示在按钮上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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