按钮始终显示在FrameLayout的顶部 [英] Button always displays on top in FrameLayout
本文介绍了按钮始终显示在FrameLayout的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的FrameLayout:
I have FrameLayout like this:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeColor"
android:text="new button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text"/>
</FrameLayout>
问题在于,当FrameLayout类概述告诉我们时,按钮显示在顶部:子视图是在堆栈中绘制的,最近添加的子视图在顶部".
The problem is that the button is displayed on top while FrameLayout class overview tells us this: "Child views are drawn in a stack, with the most recently added child on top".
推荐答案
Lollipop及更高版本中的按钮具有默认的标高,即 使它们始终位于顶部.您可以通过覆盖来更改此设置 默认的StateListAnimator.
Buttons in Lollipop and higher have a default elevation to them which causes them to always draw on top. You can change this by overriding the default StateListAnimator.
尝试将其放入按钮XML:
Try putting this into your button XML:
android:stateListAnimator="@null"
FrameLayout现在应该覆盖 按钮.
The FrameLayout should now cover the button.
这篇关于按钮始终显示在FrameLayout的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文