【问题标题】:Incorrect overlay behavior in FrameLayoutFrameLayout 中的覆盖行为不正确
【发布时间】:2015-10-08 13:48:50
【问题描述】:

根据docs,FrameLayout 中的子视图被绘制在彼此的顶部,最近添加的视图在顶部。不过我注意到,这在 Lollipop 或更高版本中似乎不准确。例如,在以下 xml 中,按钮仍然可见,即使它应该被我的自定义视图覆盖。

值得一提的是,虽然我的自定义视图扩展了 FrameLayout,但我确实膨胀了一个子视图,所以我的 FrameLayout 不是空的。

<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>

知道我在这里缺少什么吗?

【问题讨论】:

标签: android android-layout


【解决方案1】:

Lollipop 及更高版本中的按钮具有默认高度,这导致它们始终绘制在顶部。您可以通过覆盖默认的StateListAnimator 来更改此设置。

尝试将其放入您的按钮 XML:

android:stateListAnimator="@null"

FrameLayout 现在应该覆盖按钮。

【讨论】:

  • 你也应该回复this question
  • @RahulTiwari 嗯...不确定这是同一个问题。
  • @Rahul Tiwari 麻烦的是为该问题提供的答案并不令人满意。
  • 这就是为什么我要求@drschultz 写一个答案。
  • 完美运行。
【解决方案2】:

尝试为 FrameCustom 设置高程:

<mycustomframelayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        android:elevation="100dp"/>

【讨论】:

  • android 的默认按钮高度是多少?
猜你喜欢
  • 2020-05-12
  • 2019-12-16
  • 2014-05-17
  • 1970-01-01
  • 2017-07-09
  • 1970-01-01
  • 2022-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多