【发布时间】:2015-01-20 17:15:32
【问题描述】:
在 SDK 管理器的 Android 5.0 示例中,有 ElevationBasic 示例。它显示了两个View 对象:一个圆形和一个正方形。圈子已将android:elevation 设置为30dp:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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">
<View
android:id="@+id/floating_shape"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginRight="40dp"
android:background="@drawable/shape"
android:elevation="30dp"
android:layout_gravity="center"/>
<View
android:id="@+id/floating_shape_2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="25dp"
android:background="@drawable/shape2"
android:layout_gravity="center"/>
</FrameLayout>
在 Nexus 9 上,按原样运行示例,我们会在圆圈上看到阴影:
如果我们将小部件类更改为Button,保留所有其他属性不变,我们将失去圆圈上的阴影:
问题:
为什么
android:elevation的行为会发生变化?不可能是因为背景,因为这两种情况的背景是一样的。哪些类支持
android:elevation,哪些不支持?例如,使用TextView而不是View或Button仍然会给我们阴影,因此这种行为变化不是在TextView级别引入,而是在Button级别引入。从昨天的this question 中可以看出,我们如何让
android:elevation在Button上获得荣誉?是否有一些android:allowElevationToWorkAsDocumented="true"值需要我们添加到主题或其他内容中?
【问题讨论】:
-
有趣的问题和发现,您可以与我们分享测试项目的任何更改吗?
-
@Rolfツ:同样,它是 Android 5.0 示例中的
ElevationBasic示例,您可以从 SDK 管理器下载。我没有编写示例,尽管我按照Button测试的问题中所述对其进行了修改。 -
我的错,我读得有点快;)
标签: android android-5.0-lollipop