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

查看:28
本文介绍了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) 应用到按钮,但它没有改变任何东西.所以我想知道它是否需要处理海拔.

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.

推荐答案

您可以在 ProgressBar 中添加 android:translationZ 属性:

You can add the android:translationZ attribute to the 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天全站免登陆