Mic*_*sin 3 android views material-design android-elevation
最近,我惊讶于一个问题。在我的android手机上,具有相同高度的列表或滚动视图的元素具有与其位置相关的不同阴影。例如,每当屏幕底部的视图具有更暗和更强的阴影时,屏幕顶部的视图将具有较小的光影。这是Google Keep应用程序的屏幕截图:
因此,我认为这完全是因为Google Keep应用程序。也许Google的家伙决定为他们的应用程序添加阴影。因此,我创建了一个示例应用程序。
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
<TextView
style="@style/AppButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Test"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的风格:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppButton">
<item name="android:background">@color/colorAccent</item>
<item name="android:elevation">4dp</item>
<item name="android:gravity">center</item>
<item name="android:padding">16dp</item>
<item name="android:textColor">@android:color/white</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
输出为:
如您所见,我们具有相同的效果(顶视图阴影很小,底视图阴影很大)。所以我的问题是:
PS:我有Nexus 5X,Android 7.1.2。
UPD: 一个重要的提示,从Android Studio预览窗口中,一切都很好。每个视图都有相同的阴影。但是在实际设备上,您可以看到不同之处。
由Elevation API生成的阴影位于3D空间中,这意味着每个阴影的外观不仅受其高低值的影响,还受到阴影投射器在屏幕上的x和y位置的影响。这与现实世界非常相似-光源下的物体投射的阴影比远处的物体要短。
仔细看看您发布的第一张图片。左侧卡的左侧边缘和右侧卡的右侧边缘上的阴影比水平中心处的阴影更长。
广告。1.没事。就是这样。
广告。2.无法使用Elevation API。您可以自己绘制阴影。
广告。3.不知道,对不起。
广告。4.所有设备。
广告。UPD。编辑器中的阴影是静态的,因此您没有观察到任何效果。
归档时间: |
|
查看次数: |
1236 次 |
最近记录: |