简体   繁体   English

Android图像视图底部阴影

[英]Android image view bottom shadow

How can i make recycle view item like this(shadow) in android? 如何在Android中制作像这样的回收视图项目(阴影)?

https://dribbble.com/shots/4020189-Scroll-and-sidebar-interaction https://dribbble.com/shots/4020189-Scroll-and-sidebar-interaction

For adding shadow, you can use a code like this: 要添加阴影,可以使用如下代码:

Paint forShadow = new Paint(); 

// radius=10, y-offset=2, color=black 

forShadow.setShadowLayer(10.0f, 0.0f, 2.0f, 0xFF000000); 

// in onDraw(Canvas) method 

canvas.drawBitmap(bitmap, 0.0f, 0.0f, forShadow);

Also for Honeycomb and above you need to invoke setLayerType(LAYER_TYPE_SOFTWARE, forShadow) , otherwise you will not see your shadow! 同样对于Honeycomb及更高版本,您需要调用setLayerType(LAYER_TYPE_SOFTWARE, forShadow) ,否则您将看不到阴影!

SetShadowLayer does not work with hardware acceleration unfortunately so it greatly reduces performances. 不幸的是, SetShadowLayer无法与硬件加速一起使用,因此会大大降低性能。

Full code may look something like this in brief: 完整的代码可能看起来像这样简短:

public class ShadowImage extends Drawable {

Bitmap bm;

@Override
public void draw(Canvas canvas) {

    Paint forShadow = new Paint();
    //trying for rectangle
    Rect rect = new Rect(0,0,bm.getWidth(), bm.getHeight());

    forShadow.setAntiAlias(true);
    forShadow.setShadowLayer(5.5f, 4.0f, 4.0f, Color.BLACK);

    canvas.drawRect(rect, forShadow);
    canvas.drawBitmap(bm, 0.0f, 0.0f, null);

}

public ShadowImage(Bitmap bitmap) {
    super();
    this.bm = bitmap;
} ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM