Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize multiple ImageView dragging and exchanging pictures in live broadcasting room

Shulou Source: shulou.com Published: 2022-06-02 20:57:04 10月01日 Update

This article mainly explains "how to achieve multiple ImageView drag and drop interchange pictures in live broadcasting". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to achieve multiple ImageView drag and drop interchange pictures in live streaming".

The first is the XML file code:

It is important to note that the two ImageView should be installed separately with Layout, and the reason will be explained later.

Next is initialization: mImg0 = findViewById (R.id.release_img0); mImg1 = findViewById (R.id.release_img1); mImg0_layout = findViewById (R.id.release_img0_layout); mImg1_layout = findViewById (R.id.release_img1_layout); / / add touch snooping for ImageView and drag snooping for their respective parent layouts mImg0.setOnTouchListener (ImgUtils.MyTouchEvent); mImg0_layout.setOnDragListener (ImgUtils.MyDragListener); mImg1.setOnTouchListener (ImgUtils.MyTouchEvent); mImg1_layout.setOnDragListener (ImgUtils.MyDragListener) Monitoring details: public class ImgUtils {private static long lastTime; public static View.OnTouchListener MyTouchEvent = new View.OnTouchListener () {@ Override public boolean onTouch (View v, MotionEvent event) {if (event.getAction () = = MotionEvent.ACTION_DOWN) {LogUtils.loge ("ACTION_DOWN"); long lastTime1 = System.currentTimeMillis (); lastTime=lastTime1 ClipData data = ClipData.newPlainText ("", "); View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder (v); v.startDrag (data, shadowBuilder, v, 0); if ((lastTime1-lastTime)

Tags: Event monitor multiple picture studio live conflict layout thought control learning content reason child time core next one side two code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MariaDB NVidia Redmi vpn