Android提升属性不起作用

时间:2014-11-08 01:28:28

标签: android android-layout

自升级到SDK 21以来,我一直在尝试使用提升属性,但似乎无法正常工作。

我想提升一个框架高于其他框架,所以我设置了以下

android:elevation="4dp"

但没有阴影的迹象。我尝试了按钮和framelayouts但没有任何提升

所以这里是完整的标签

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/panel_card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:elevation="4dp"
    >

我错过了我需要添加的其他内容

3 个答案:

答案 0 :(得分:31)

确保持有FrameLayout的容器的背景不透明。

答案 1 :(得分:1)

根据this Z = Elevation + TranslationZ

所以试试这个:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:card_view="http://schemas.android.com/apk/res-auto"
  android:id="@+id/panel_card"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="#ffffff"
  android:elevation="4dp"
  android:translationZ="4dp">

答案 2 :(得分:1)

您需要为其添加背景,例如:

https://www.c-sharpcorner.com/article/simple-login-application-using-Asp-Net-mvc/

而不是使用白色。否则,阴影将不起作用。另外,也不必使用android:translationZ属性,因为它只会添加到高程中,但是如果您不想使用动画,则不需要。

相关问题