android - 如何调整 DragShadowBuilder 的大小?
问题描述
我DragShadowBuilder
在一个ImageView
.
val data = ClipData.newPlainText("", "")
dragShadow = MyDragShadowBuilder(imageViewTemp, imageLayout.width, imageLayout.width)
imageViewTemp.startDragAndDrop(data, dragShadow, imageViewTemp, View.DRAG_FLAG_OPAQUE)
如您所见,我已经设置了 的宽度和高度DragShadowBuilder
,但我想将其调整为 250,当它被拖动时。我怎样才能做到这一点?如果我不能调整它的大小,我可以重新创建DragShadowBuilder
一些减少宽度和高度的?
class MyDragShadowBuilder(
view: View,
val scaledWidth: Int,
val scaledHeight: Int
) : View.DragShadowBuilder(view) {
var tempScaleX = 0.0F
var tempScaleY = 0.0F
override fun onProvideShadowMetrics(outShadowSize: Point?, outShadowTouchPoint: Point?) {
// calculate the scaled view's dimensions
tempScaleX = scaledWidth.toFloat() / view.width
tempScaleY = scaledHeight.toFloat() / view.height
// set the scaled shadow size
outShadowSize?.set(scaledWidth, scaledHeight)
// re-center the out touch point using the scaled dimensions
outShadowTouchPoint?.set(scaledWidth / 2, scaledHeight / 2)
}
override fun onDrawShadow(canvas: Canvas?) {
// scale the canvas so it can fit the scaled view
canvas?.scale(
tempScaleX,
tempScaleY
)
view.draw(canvas)
}
}
解决方案
推荐阅读
- angular - Ionic/Angular + Lottie:分别为每个 Lottie 设置动画?
- c++ - C++ - x64 进程的 VirtualQueryEx
- varnish - 使用清漆从不同位置拍摄图像
- single-sign-on - 为 discourse-openid-connect 正确地将客户端机密存储在数据库中
- python - Seaborn 线图直到最大值才绘制
- python - 使用 BeautifulSoup4 进行数据抓取的问题
- python - 使用 paramiko 在后台运行远程命令
- html - 使用 BS4 解析日期
- android - 如何从 Flutter PlatformView(Android kotlin 端)返回我的原生 android 活动
- time-complexity - 三重嵌套循环函数的时间复杂度