问题描述
按照中的FrameLayout子视图上绘制彼此的顶部,顶部的一个最近添加的图。虽然我已经注意到了,这似乎不符合棒棒糖或更高准确。例如,在下面的XML,按钮仍是可见的,尽管它应该通过我的定制视图覆盖。
According to the docs, child views in FrameLayout are drawn on top of each other with the most recently added view on top. I have notice though, that this seems to not be accurate in Lollipop or later. For example, in the following xml, the button is still visible even though it should be covered by my custom view.
值得一提的是,虽然我的自定义视图扩展的FrameLayout,我做的充气子视图,所以我的FrameLayout是不是空的。
It is worth mentioning that although my custom view extends FrameLayout, I do inflate a child view, so my FrameLayout isn't empty.
<FrameLayout
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=".MainActivity">
<Button
android:id="@+id/some_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="button"/>
<mycustomframelayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"/>
</FrameLayout>
任何想法,我在这里丢失?
Any idea what I am missing here?
推荐答案
在棒棒糖按钮和较高的有一个默认的海拔给他们,导致他们始终在最前面借鉴。您可以通过重写默认。
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覆盖行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!