Android拖放startDragAndDrop拖拽Glide加载堆叠圆角图,Kotlin(5)

Android拖放startDragAndDrop拖拽Glide加载堆叠圆角图,Kotlin(5)

 

 

import android.content.ClipData
import android.graphics.Canvas
import android.graphics.Point
import android.os.Bundle
import android.util.Log
import android.view.DragEvent
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnDragListener
import android.view.View.OnLongClickListener
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCornersclass MainActivity : AppCompatActivity() {companion object {const val TAG = "fly"const val DEGREE = -10 //图片选择的角度。const val RADIUS = 30 //图片的圆角半径。}override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val shadowBuilder = createDragShadowBuilder()setData(shadowBuilder.getShadowView())val triggerView = findViewById<ImageView>(R.id.image)triggerView.setOnLongClickListener(object : OnLongClickListener {//长按事件触发拖拽.override fun onLongClick(v: View?): Boolean {val data = ClipData.newPlainText("name", "phil") //测试数据。triggerView.startDragAndDrop(data,shadowBuilder,null,0 or View.DRAG_FLAG_GLOBAL or View.DRAG_FLAG_OPAQUE)return true}})triggerView.setOnDragListener(object : OnDragListener {override fun onDrag(v: View?, event: DragEvent?): Boolean {when (event?.action) {DragEvent.ACTION_DRAG_STARTED -> {//拖放开始Log.d(TAG, "ACTION_DRAG_STARTED")//updateData(shadowView)}DragEvent.ACTION_DRAG_ENTERED -> {//进入imageViewLog.d(TAG, "ACTION_DRAG_ENTERED")}DragEvent.ACTION_DRAG_ENDED -> {//拖放结束Log.d(TAG, "ACTION_DRAG_ENDED")}DragEvent.ACTION_DRAG_EXITED -> {//离开imageViewLog.d(TAG, "ACTION_DRAG_EXITED")}}return true}})}private fun createDragShadowBuilder(): MyDragShadowBuilder {val shadowView = LayoutInflater.from(this).inflate(R.layout.dnd, null)return MyDragShadowBuilder(shadowView)}private fun setData(viewGroup: View) {//从1和4两个数字中随机选一个。var cnt = intArrayOf(1, 4).random()Log.d(TAG, "cnt=$cnt")val group: androidx.constraintlayout.widget.Group = viewGroup.findViewById(R.id.group)val number = viewGroup.findViewById<TextView>(R.id.number)if (cnt == 1) {//只显示一张。number.text = "1"group.visibility = ViewGroup.INVISIBLE} else if (cnt == 4) {//显示重叠在一起的4张。number.text = "4"group.visibility = ViewGroup.VISIBLEval imageViews = arrayOf(viewGroup.findViewById<ImageView>(R.id.iv1),viewGroup.findViewById<ImageView>(R.id.iv2),viewGroup.findViewById<ImageView>(R.id.iv3))val resIds = arrayOf(R.mipmap.pic1,R.mipmap.pic2,R.mipmap.pic3)imageViews.forEachIndexed { index, iv ->val degree = (imageViews.size - index) * DEGREELog.d(TAG, "index=$index degree=$degree")iv.rotation = degree.toFloat()GlideApp.with(this).load(resIds[index]).transform(CenterCrop(), RoundedCorners(RADIUS)) //先中心缩放,再切圆角。.override(resources.getDimensionPixelSize(R.dimen.image_size_w),resources.getDimensionPixelSize(R.dimen.image_size_h)).placeholder(R.drawable.ic_launcher_foreground).error(android.R.drawable.stat_notify_error).into(iv)}}val folder = viewGroup.findViewById<ImageView>(R.id.folder)//封面GlideApp.with(this).load(R.mipmap.pic4).transform(CenterCrop(), RoundedCorners(RADIUS)) //先中心缩放,再切圆角。.override(resources.getDimensionPixelSize(R.dimen.image_size_w),resources.getDimensionPixelSize(R.dimen.image_size_h)).placeholder(R.drawable.ic_launcher_foreground).error(android.R.drawable.stat_notify_error).into(folder)}class MyDragShadowBuilder(private var mShadow: View) :View.DragShadowBuilder() {private val width: Int =mShadow.context.resources.getDimensionPixelSize(R.dimen.view_size_w)private val height: Int =mShadow.context.resources.getDimensionPixelSize(R.dimen.view_size_h)fun getShadowView(): View {return mShadow}override fun onProvideShadowMetrics(outShadowSize: Point?, outShadowTouchPoint: Point?) {//拖动图像的宽和高outShadowSize?.set(width, height)//手指在拖动图像的位置 中点outShadowTouchPoint?.set(width / 2, height / 2)}override fun onDrawShadow(canvas: Canvas) {mShadow.measure(width, height)mShadow.layout(0, 0, width, height)mShadow.draw(canvas)Log.d(TAG, "onDrawShadow width=$width height=$height")}}
}

 

 

只有一张图片,只显示封面图:

fc388ed6edac4355962b9ab81cab9004.png

 

 

 

多张图片,显示堆叠的图片,并同时设置封面图: 

aefdc47b6caf4c18b48cb358e7bc7aaa.png

 

 

dnd.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="@dimen/view_size_w"android:layout_height="@dimen/view_size_h"android:background="@android:color/holo_orange_light"><ImageViewandroid:id="@+id/iv1"android:layout_width="@dimen/image_size_w"android:layout_height="@dimen/image_size_h"android:layout_margin="@dimen/my_margin"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><ImageViewandroid:id="@+id/iv2"android:layout_width="@dimen/image_size_w"android:layout_height="@dimen/image_size_h"android:layout_margin="@dimen/my_margin"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><ImageViewandroid:id="@+id/iv3"android:layout_width="@dimen/image_size_w"android:layout_height="@dimen/image_size_h"android:layout_margin="@dimen/my_margin"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><androidx.constraintlayout.widget.Groupandroid:id="@+id/group"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="visible"app:constraint_referenced_ids="iv1,iv2,iv3" /><ImageViewandroid:id="@+id/folder"android:layout_width="@dimen/image_size_w"android:layout_height="@dimen/image_size_h"android:layout_margin="@dimen/my_margin"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><TextViewandroid:id="@+id/number"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@android:color/holo_red_light"android:text="--"android:textColor="@android:color/white"android:textSize="30dp"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

 

 

dimens.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources><dimen name="view_size_w">250dp</dimen><dimen name="view_size_h">200dp</dimen><dimen name="image_size_w">150dp</dimen><dimen name="image_size_h">100dp</dimen><dimen name="my_margin">50dp</dimen>
</resources>

 

 

 

Android拖放startDragAndDrop拖拽onDrawShadow静态添加xml布局View,Kotlin(4)-CSDN博客文章浏览阅读74次。Android DynamicGrid:拖曳交换位置Android DynamicGrid是一个第三方开源项目,DynamicGrid在github上的项目主页是:https://github.com/askerov/DynamicGrid它实现在一个网格布局内,拖曳任意子view实现动态的交换位置,这很类似手机的桌面,手机桌面的图标,均可自由拖曳实现摆放位置的交换,如动图所示:_android 拖拽交换位置。Android View拖拽startDragAndDrop,Kotlin-CSDN博客。https://blog.csdn.net/zhangphil/article/details/134017828

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/138684.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Echarts柱状体实现滚动条动态滚动

当我们柱状图中X轴数据太多的时候&#xff0c;会自动把柱形的宽度挤的很细&#xff0c;带来的交互非常不好&#xff0c;因此就有一个属性来解决&#xff1a;dataZoom 第一种简易的版本&#xff0c;横向滚动。 dataZoom: {show: true, // 为true 滚动条出现realtime: true, // 实…

含免费次数的API接口资源分享

全国招投标查询&#xff1a;查询招标保标信息&#xff0c;涵盖招标信息查询、中标信息查询、VIP项目、拟在建项目、业主委托项目、PPP项目、项目来源、历史招标库、政府采集信息、招标定制、订阅推送、订阅导出、数据下载等数十个招投标领域。AI绘画-Mid Journey&#xff1a;使…

hdlbits系列verilog解答(反转向量位序)-40

文章目录 一、问题描述二、verilog源码三、仿真结果一、问题描述 给定一个 100 位输入向量 [99:0],反转其位顺序。 Module Declaration module top_module( input [99:0] in, output [99:0] out ); 二、verilog源码 module top_module( input [99:0] in,output [99:0

Leetcode 299. Bulls and Cows

Problem You are playing the Bulls and Cows game with your friend. You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info: The number of “bulls”, which …

RabbitMQ集群配置以及负载均衡配置

RabbitMQ集群配置以及负载均衡配置 环境配置集群配置安装rabbitmq启动rabbitmq开启远程登录添加用户并且授权用户添加数据存放目录和日志存放目录查看端口拷⻉erlang.cookie将mq-2、mq-3作为内存节点加⼊mq-1节点集群中查看集群状态添加一个新的队列 RabbitMq负载均衡配置-HAPr…

【ChatGLM2-6B】小白入门及Docker下部署

【ChatGLM2-6B】小白入门及Docker下部署 一、简介1、ChatGLM2是什么2、组成部分3、相关地址 二、基于Docker安装部署1、前提2、CentOS7安装NVIDIA显卡驱动1&#xff09;查看服务器版本及显卡信息2&#xff09;相关依赖安装3&#xff09;显卡驱动安装 2、 CentOS7安装NVIDIA-Doc…

常用SQL——IF介绍

在SQL中&#xff0c;IF语句用于根据条件执行不同的操作。下面是一个简单的教程&#xff0c;介绍如何在不同的数据库中使用IF语句。 1. MySQL中的IF语句&#xff1a; sql IF(condition, true_value, false_value) 在MySQL中&#xff0c;IF函数接受一个条件表达式&#xff0c…

自主开发刷题应用网站H5源码(无需后端无需数据库)

该应用使用JSON作为题库的存储方式&#xff0c;层次清晰、结构简单易懂。 配套的word模板和模板到JSON转换工具可供使用&#xff0c;方便将题库从word格式转换为JSON格式。 四种刷题模式包括顺序刷题、乱序刷题、错题模式和背题模式&#xff0c;可以根据自己的需求选择适合的模…

计网----累积应答,TCP的流量控制--滑动窗口,粘包问题,心跳机制,Nagle算法,拥塞控制,TCP协议总结,UDP和TCP对比,中介者模式

计网----累积应答&#xff0c;TCP的流量控制–滑动窗口&#xff0c;粘包问题&#xff0c;心跳机制&#xff0c;Nagle算法&#xff0c;拥塞控制&#xff0c;TCP协议总结&#xff0c;UDP和TCP对比&#xff0c;中介者模式 一.累积应答 1.什么是累计应答 每次发一些包&#xff0…

Leetcode刷题详解—— 组合总和

1. 题目链接&#xff1a;39. 组合总和 2. 题目描述&#xff1a; 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target &#xff0c;找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 &#xff0c;并以列表形式返回。你可以按 任意顺序 返回这些…

Pytorch实战教程(十一)-卷积神经网络

0. 前言 卷积神经网络 (Convolutional Neural Network, CNN) 是一种非常强大的深度学习模型,广泛应用于图像分析、目标检测、图像生成等任务中。CNN 的核心思想是卷积操作和参数共享,卷积操作通过滑动滤波器(也称为卷积核)在输入数据上进行元素级的乘积和求和运算,从而提取…

uniapp蓝牙搜索设备并列表展示

1.需求&#xff1a;3.0的桩可以值扫码通过蓝牙名字直接绑定&#xff0c;2.0的桩二维码无蓝牙名称则需通过蓝牙列表来绑定 2.碰到问题 1.0 蓝牙列表需要去重&#xff08;蓝牙列表通过deviceId去重再放进展示列表&#xff09; 2.0页面会卡顿&#xff08;调用my.stopBluetoothDevi…

docker部署mongodb

1&#xff1a;拉去momgodb镜像 2&#xff1a;拉去成功后&#xff0c;通过docker-compose.yml配置文件启动mongodb&#xff0c;docker-compose.yml配置如下 version: 3.8 services:mongodb-1:container_name: mongodbimage: mongo ports:- "27017:27017"volumes:- G:…

Python Selenium元素定位方法详解

引言 在Web自动化测试中&#xff0c;元素定位是一项非常重要的技术。Python Selenium提供了各种元素定位方法&#xff0c;可以帮助我们定位页面上的元素并与之交互。本文将详细介绍Python Selenium中常用的元素定位方法&#xff0c;并提供实例代码。 1. ID定位 ID是元素在HT…

java入门,记一次微服务间feigin请求的问题

一、前言 记录工作中遇到的开发问题&#xff0c;而不是写博客凑字数。 二、微服务调用 1、通过本服务调用另外一个服务&#xff0c;需要定义一个接口&#xff0c;并用FeignClient 注解进行注解 value "服务名" 要调用的服务名 服务得到路径&#xff0c;对应的是c…

使用CompletableFuture进行异步编程

CompletableFuture是Java 8中引入的一个异步编程工具&#xff0c;它实现了Future和CompletionStage接口&#xff0c;可以用于处理异步任务。CompletableFuture提供了丰富的方法&#xff0c;可以方便地组合多个异步任务&#xff0c;实现复杂的异步逻辑。本文将介绍CompletableFu…

iOS 设置图标和upload包时显示错误

右键-show in finder-AppIcon.appiconset-然后替换图片 然后遇到个问题 就是图片不能有alpha [Xcode]应用图标&#xff1a;ERROR ITMS-90717: “Invalid App Store Icon. The App Store Icon in the asset catalog in x… 具体操作&#xff1a;只需确保【AppIcon】图片集中不…

test_sizeof

test_sizeof //结论&#xff1a; // sizeof(arrU8)得到的大小是u8类型数组的 **定义大小**&#xff0c;在 初始化的时候用 // strlen(arrU8)得到的大小是u8类型数组的 **实际大小**&#xff0c;在 复制的时候用 //sizeof((char*)arrU8)&#xff0c;把一个u8 * 转成 char *&…

(层次遍历)111. 二叉树的最小深度

原题链接&#xff1a;111. 二叉树的最小深度 思路&#xff1a; 直接层序遍历&#xff0c;遍历一层记录最小深度的遍历depth 最先遇到叶子节点就代表是最小的深度&#xff0c;直接返回depth即可 全代码&#xff1a; class Solution { public:int minDepth(TreeNode* root) {q…

java笔记(一)

一、Java的三大平台 1.Java SE (必学) java语言的标准版&#xff0c;用于桌面开发&#xff0c;是其他两个版本的基础。 桌面应用适合的语言其实是c和C合适&#xff0c;复杂动画等加载时java很慢。 2.Java ME(现在很少用) java语言的小型版本&#xff0c;适用于嵌入式电子设备或…