关于DragShadowBuilder无法显示阴影问题探究
来源:互联网 发布:女孩冬季外穿短裤淘宝 编辑:程序博客网 时间:2024/05/16 04:43
DragShadowBuilder是新版安卓拖放时的一个辅助类,是在手势拖动的时候动态显示拖动的阴影,这个阴影可以放置图片,也可以自己用画布画
构造方法
View.DragShadowBuilder(View):
这个构造器接收任意的应用程序的View对象。这个构造器把View对象保存在View.DragShadowBuilder对象中,以便在回调期间访问这个View对象,来构造拖拽影子。它(View对象参数)不必跟用户选择的开始拖拽操作的View对象相关联。
如果使用这个构造器,就不必扩展View.DragShadowBuilder类或覆写它的方法。默认情况,你会获得一个跟传递给构造器的View对象外观相同的拖拽影子。在用户的触屏位置下方,以出点为中心显示。
View.DragShadowBuilder():
如果使用这个构造器,在ViewDragShadowBuilder对象中没有有效的View对象。默认情况下,如果使用这个构造器,并且没有扩展View.DragShadowBuilder类或覆写它的方法,那么就会获得一个不可见的拖拽影子,系统不会给出错误。
相关的翻译已经有很多,但是不知道为什么没有去实验一下,反正我的实验结果是单纯的用View.DragShadowBuilder(View)是无法显示阴影的,当然我传入的是imageview,然后我就去stackoverflow上搜索,果然也有人有相同问题
链接http://stackoverflow.com/questions/11757115/why-dragshadowbuilder-doesnt-show-imageview
下面的有一种猜测:ImageView is not being drawn until it is added to a layout
所以解决方案为重写DragShadowBuilder传入一个位图,自己画
public class LJDragShadowBuilder extends View.DragShadowBuilder { private Bitmap image; // image to draw as a drag shadow public LJDragShadowBuilder(Bitmap _image) { super(); image = _image; } public void onDrawShadow(Canvas canvas) { canvas.drawBitmap(image, 0, 0, null); } public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { shadowSize.x = image.getWidth(); shadowSize.y = image.getHeight(); shadowTouchPoint.x = shadowSize.x / 2; shadowTouchPoint.y = shadowSize.y / 2; }}这个方法我证实过可行,同时研究android给的例子可以看到,它也是继承一个自己画的,跟传进来的view没半毛钱关系,只是super给父类了。。。
private static class MyDragShadowBuilder extends View.DragShadowBuilder { // The drag shadow image, defined as a drawable thing private static Drawable shadow; // Defines the constructor for myDragShadowBuilder public MyDragShadowBuilder(View v) { // Stores the View parameter passed to myDragShadowBuilder. super(v); // Creates a draggable image that will fill the Canvas provided by the system. shadow = new ColorDrawable(Color.LTGRAY); } // Defines a callback that sends the drag shadow dimensions and touch point back to the // system. @Override public void onProvideShadowMetrics (Point size, Point touch) // Defines local variables private int width, height; // Sets the width of the shadow to half the width of the original View width = getView().getWidth() / 2; // Sets the height of the shadow to half the height of the original View height = getView().getHeight() / 2; // The drag shadow is a ColorDrawable. This sets its dimensions to be the same as the // Canvas that the system will provide. As a result, the drag shadow will fill the // Canvas. shadow.setBounds(0, 0, width, height); // Sets the size parameter's width and height values. These get back to the system // through the size parameter. size.set(width, height); // Sets the touch point's position to be in the middle of the drag shadow touch.set(width / 2, height / 2); } // Defines a callback that draws the drag shadow in a Canvas that the system constructs // from the dimensions passed in onProvideShadowMetrics(). @Override public void onDrawShadow(Canvas canvas) { // Draws the ColorDrawable in the Canvas passed in from the system. shadow.draw(canvas);}}你看它画的是drawable,跟传进来的view有半毛钱关系么。。。
希望有大牛能够进来指教一下
- 关于DragShadowBuilder无法显示阴影问题探究
- 关于CardView无法显示阴影的问题
- 关于阴影的问题
- 安卓下不显示阴影的问题
- 关于无法显示特殊汉字的问题
- 关于GLSurfaceView无法显示的问题
- 关于qt无法显示汉字的问题
- 关于QLabel无法显示的问题
- 关于Android中的elevation阴影显示条件
- 液晶显示器显示发虚模糊阴影的问题
- SuperMap for Javascript 气泡阴影显示问题
- 关于博客无法正确显示后台信息的问题
- 关于win32绘图出现无法显示彩色问题的解决
- eclipse3.2 关于VSS状态图标无法显示问题
- 关于chm无法显示的问题(已解决)
- 关于系统托盘图标(systemtray)无法显示问题的解决
- 关于开机显示GRUB 无法正常进入系统的问题
- 关于系统托盘图标(systemtray)无法显示问题的解决
- 算法之美---由计算机生成的图像
- 简单的设置用户名以及密码的登录
- Qt直接打开已知的URL,也可用于下载
- 目标黑马,我的自学之路:第十四章 拷贝多级目录实例
- 【自考】信息系统开发与管理(三)——考后总结
- 关于DragShadowBuilder无法显示阴影问题探究
- Oracle Rman跨resetlogs版本恢复
- c++类继承内存布局的
- c语言的自动类型转换
- asyncTask简单应用
- 第八周项目5 定期利息计算器
- 剪贴板监听器
- #define 用法
- 内网ip的获取