
最近,我对一个问题感到惊讶.在我的Android手机上,列表中的元素或具有相同高程的滚动视图具有与其定位相关的不同阴影.例如,屏幕顶部的视图具有小的光影,只要屏幕底部的视图具有更暗和强阴影.以下是Google Keep应用程序的屏幕截图:
所以,我认为这是因为谷歌Keep应用程序.也许谷歌的人决定用阴影来做他们的应用.因此,我创建了一个示例应用程序.
我的布局:
<?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 androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margin="16dp" androID:text="Test"/></linearLayout>我的风格:
<?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>输出是:
如你所见,我们有相同的效果(顶视图有一个小阴影,底视图有一个大阴影).所以我的问题是:
>我做错了什么?
>如何为所有视图实现相同的阴影(根据其位置不同)?
>另外,我没有在文档中找到任何解释,所以在哪里我可以读到这个现象?
>它是在所有设备上发生还是仅在特定设备上发生?
P.S.:我有Nexus 5X,AndroID 7.1.2.
UPD:
重要提一下,从AndroID Studio PrevIEw Window一切都很好.每个视图都与其他视图具有相同的阴影.但在真实设备上,您可以看到差异.
解决方法:
Elevation API生成的阴影位于3D空间中,这意味着每个阴影的外观不仅受其高程值的影响,还受影子施法者在屏幕上的x和y位置的影响.它与现实世界非常相似 – 光源下方的物体比远处的物体投射出更短的阴影.
仔细查看您发布的第一张图片.左卡的左边缘和右卡的右边缘的阴影比水平中心的边缘长.
广告.没什么.它只是这样工作.
广告. 2.使用Elevation API是不可能的.你可以自己画阴影.
广告.不知道,对不起.
广告. 4.所有设备.
广告. UPD.编辑器中的阴影是静态的,因此您没有观察到任何影响.
总结以上是内存溢出为你收集整理的android – 顶视图和底视图的相同高程视图看起来不同全部内容,希望文章能够帮你解决android – 顶视图和底视图的相同高程视图看起来不同所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)