[已解决]Android 5.0之后的机器上面, Android Button 总是显示在FrameLayout的最前面

在Android 5.0及更高版本中,由于Material Design的引入,Button默认的TranslationZ导致其显示在其他视图之上。通过设置TextView的TranslationZ或Elevation值高于Button的Z值,或者将Button的StateListAnimation设为null,可以避免此问题。解决方案包括在XML布局或代码中调整组件属性。
摘要由CSDN通过智能技术生成

测试了Android 5.0.1 Android 6.0.1机器上面都有这个问题。


布局代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.zhangyinshan.framelayouttest.MainActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textAlignment="center"
        android:text="Hello World!"
        android:id="@+id/hello"
        android:textSize="26sp" />
    <TextView
        android:id="@+id/up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/holo_red_light"
        android:text="UP"
        android:textSize="26sp"
        android:layout_gravity="center"
        android:textAlignment="center"
        />

</FrameLayout>





这个是因为Android 5.0之后引入了一个Material Design的概念 

https://developer.android.com/training/material/shadows-clipping.html?hl=zh-cn 


视图的 Z值包含两个组件:

  • 高度(Elevation):静态组件。Elevation
  • 转换(Translation):用于动画的动态组件。
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值