Zha*_*ang 10 android dropshadow imageview
我正在尝试向ImageView添加投影.另一个Stackoverflow答案似乎是使用画布和位图等,比它需要的方式更复杂.
在iOS上我会做这样的事情:
myImageView.layer.shadowColor = [UIColor redColor].CGColor;
myImageView.layer.shadowRadius = 5;
myImageView.layer.shadowOffset = CGRectMake(0, 5);
Run Code Online (Sandbox Code Playgroud)
它会渲染阴影,无论阴影是否应用于视图,图像或文本.
我试过在Android上做同样的事情,但它只是拒绝工作:
birdImageView = new ImageView(context);
birdImageView.setImageResource(R.drawable.yellow_bird);
Paint paint = new Paint();
paint.setAntiAlias(true);
birdImageView.setLayerType(LAYER_TYPE_SOFTWARE, null);
paint.setShadowLayer(5, 0, 5, Color.argb(255, 255, 0, 0));
birdImageView.setLayerPaint(paint);
Run Code Online (Sandbox Code Playgroud)
我的鸟图像上根本没有看到任何预期的红色阴影.
难道我做错了什么?
假设我想要这样的投影:
我是否必须使用Android 5.0和新的Elevation api(http://developer.android.com/training/material/shadows-clipping.html)?
但如果要使用新的API,那么根据当前的人口统计数据(http://www.droid-life.com/2016/02/02/android-distribution-february-2016/),超过50%的用户不会能够使用该应用程序.
T_T
Mah*_*ade 11
在android studio中drawable,你可以使用build for apply shadow to any View.这类似于投影.
android:background="@drawable/abc_menu_dropdown_panel_holo_light"
Run Code Online (Sandbox Code Playgroud)
使用此功能,您无法更改视图的背景颜色及其边框颜色.如果你想要自己的自定义drawable,那么使用layer-list
custom_drop_shadow_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
android:bottom="0dp"
android:drawable="@android:drawable/dialog_holo_light_frame"
android:left="0dp"
android:right="0dp"
android:top="0dp">
</item>
<item
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp">
<!--whatever you want in the background, here i preferred solid white -->
<shape android:shape="rectangle">
<solid android:color="@android:color/red" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
并适用于您的观点,如下所示
android:background="@drawable/custom_drop_shadow_drawable"
Run Code Online (Sandbox Code Playgroud)
希望它能帮到你!谢谢Android View阴影
| 归档时间: |
|
| 查看次数: |
20889 次 |
| 最近记录: |