czq 2 gadi atpakaļ
vecāks
revīzija
54a9bf5c86

+ 1 - 1
.idea/misc.xml

@@ -11,6 +11,7 @@
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_main.xml" value="0.1375" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_progress.xml" value="0.22" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_quxian.xml" value="0.13645833333333332" />
+        <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_sequential_drag.xml" value="0.12092391304347826" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_sound.xml" value="0.1234375" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_spine.xml" value="0.13333333333333333" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_stars.xml" value="0.12" />
@@ -19,7 +20,6 @@
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_umeng_login.xml" value="0.1" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_view.xml" value="0.25" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_web.xml" value="0.1816123188405797" />
-        <entry key="..\:/work/mozhi/qiqu/EffectDemo/app/src/main/res/layout/activity_congratulations.xml" value="0.15274949083503056" />
       </map>
     </option>
   </component>

+ 3 - 0
app/src/main/AndroidManifest.xml

@@ -101,6 +101,9 @@
         <activity
             android:name=".activity.WebActivity"
             android:screenOrientation="landscape" />
+        <activity
+            android:name=".activity.SequentialDragActivity"
+            android:screenOrientation="landscape" />
     </application>
 
 </manifest>

+ 6 - 1
app/src/main/java/com/xunao/effectdemo/activity/MainActivity.java

@@ -23,7 +23,7 @@ import java.util.Map;
 public class MainActivity extends Activity {
 
 	Button btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,
-			btn9,btn10,btn11,btn12,btn13, btn14,btn15;
+			btn9,btn10,btn11,btn12,btn13, btn14,btn15,btn16;
 	Intent intent;
 
 	@Override
@@ -119,5 +119,10 @@ public class MainActivity extends Activity {
 			intent = new Intent(MainActivity.this,WebActivity.class);
 			startActivity(intent);
 		});
+		btn16 = findViewById(R.id.btn_16);
+		btn16.setOnClickListener(v->{
+			intent = new Intent(MainActivity.this,SequentialDragActivity.class);
+			startActivity(intent);
+		});
 	}
 }

+ 121 - 0
app/src/main/java/com/xunao/effectdemo/activity/SequentialDragActivity.java

@@ -0,0 +1,121 @@
+package com.xunao.effectdemo.activity;
+
+import android.app.Activity;
+import android.content.ClipData;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RelativeLayout;
+
+import androidx.annotation.Nullable;
+
+import com.xunao.effectdemo.R;
+
+/**
+ * author : 程中强
+ * e-mail : 740479946@qq.com
+ * date : 2022/8/3116:18
+ * desc :
+ * version: 1.0
+ */
+public class SequentialDragActivity extends Activity {
+
+	private static String TAG = "SequentialDragActivity";
+	private RelativeLayout rl1,rl2,rl3,rl4,rl5;
+	private RelativeLayout view1,view2,view3,view4,view5;
+	@Override
+	protected void onCreate(@Nullable Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.activity_sequential_drag);
+		rl1 = findViewById(R.id.rl_1);
+		rl2 = findViewById(R.id.rl_2);
+		rl3 = findViewById(R.id.rl_3);
+		rl4 = findViewById(R.id.rl_4);
+		rl5 = findViewById(R.id.rl_5);
+
+		view1 = findViewById(R.id.view1);
+		view2 = findViewById(R.id.view2);
+		view3 = findViewById(R.id.view3);
+		view4 = findViewById(R.id.view4);
+		view5 = findViewById(R.id.view5);
+		setDrag(rl1,view1);
+		setDrag(rl2,view2);
+		setDrag(rl3,view3);
+		setDrag(rl4,view4);
+		setDrag(rl5,view5);
+	}
+
+	private void setDrag(View view1,View view2){
+		view2.setOnTouchListener(new View.OnTouchListener() {
+			@Override
+			public boolean onTouch(View view, MotionEvent motionEvent) {
+
+				//定义一个裁剪数据对象.随便定义一个就行,本demo用不到这个clipData.
+				ClipData clipData = new ClipData(ClipData.newPlainText("view1", "aaa"));
+
+				//定义一个拖拽阴影
+				View.DragShadowBuilder myShadow = new View.DragShadowBuilder(view);
+
+				//开始拖拽. 第三个参数在拖拽过程用来传递数据,这里我传view即被拖动的view自己,
+				//后面可在DragEvent中获得这个参数view
+				view.startDrag(clipData, myShadow, view, 0);
+
+				return false;
+			}
+		});
+		view1.setOnDragListener(onDragListener1);
+	}
+
+	View.OnDragListener onDragListener1 = new View.OnDragListener() {
+		@Override
+		public boolean onDrag(View view, DragEvent dragEvent) {
+			Log.i(TAG, "container.onDrag called======");
+			switch (dragEvent.getAction()) {
+				case DragEvent.ACTION_DRAG_STARTED://开始.当有view被拖的时候收到此事件
+//                        Log.i(TAG, "开始");
+					((View) dragEvent.getLocalState()).setVisibility(View.INVISIBLE);
+					break;
+				case DragEvent.ACTION_DRAG_ENTERED://进入.当被拖view手指按压的位置进入本view的瞬间收到此事件
+//                        Log.i(TAG, "进入");
+					break;
+				case DragEvent.ACTION_DRAG_LOCATION://位于.当被拖view手指按压的位置在本view上方的时候收到此事件
+//                        Log.i(TAG, "位于");
+
+					//此时dragEvent里包含要被拖view
+					View draggingView = (View) dragEvent.getLocalState();
+					//当前容器
+					ViewGroup thisContainer = ((ViewGroup) view);
+					//被拖拽view覆盖的view
+					View coveredView = thisContainer.getChildAt(0);
+					//当拖拽的view跟被覆盖的view不同时
+					if (draggingView != coveredView) {
+						ViewGroup draggingViewContainer = (ViewGroup) draggingView.getParent();
+						//两个容器交换子view
+						thisContainer.removeView(coveredView);
+						draggingViewContainer.removeView(draggingView);
+						thisContainer.addView(draggingView);
+						draggingViewContainer.addView(coveredView);
+					}
+					break;
+				case DragEvent.ACTION_DROP://丢入.当被拖view在本view上方手指释放开,收到此事件
+//                        Log.i(TAG, "丢入");
+					Log.i(TAG, "丢入view_container2");
+					break;
+				case DragEvent.ACTION_DRAG_EXITED://出去.当被拖view手指按压位置从本view拖出去收到此事件
+//                        Log.i(TAG, "出去");
+					break;
+				case DragEvent.ACTION_DRAG_ENDED://结束.手指释放拖拽结束收到此事件.
+//                        Log.i(TAG, "结束");
+					((View) dragEvent.getLocalState()).setVisibility(View.VISIBLE);
+					break;
+				default:
+					break;
+			}
+			//一定要为true
+			return true;
+		}
+	};
+}

+ 5 - 0
app/src/main/res/layout/activity_main.xml

@@ -97,6 +97,11 @@
             android:text="小游戏"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"/>
+        <Button
+            android:id="@+id/btn_16"
+            android:text="顺序拖拽"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"/>
     </LinearLayout>
 
 </ScrollView>

+ 160 - 0
app/src/main/res/layout/activity_sequential_drag.xml

@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+
+    <RelativeLayout
+        android:id="@+id/rl_1"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        android:layout_marginLeft="100dp"
+        android:layout_width="100dp"
+        android:layout_height="100dp">
+
+        <RelativeLayout
+            android:id="@+id/view1"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+            <com.xuexiang.xui.widget.imageview.RadiusImageView
+                app:riv_corner_radius="100dp"
+                android:src="@color/colorAccent"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+
+            <TextView
+                android:textSize="30sp"
+                android:text="1"
+                android:textColor="@color/colorWhite"
+                android:gravity="center"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+        </RelativeLayout>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_2"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        android:layout_marginLeft="200dp"
+        android:layout_width="100dp"
+        android:layout_height="100dp">
+
+        <RelativeLayout
+            android:id="@+id/view2"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+            <com.xuexiang.xui.widget.imageview.RadiusImageView
+                app:riv_corner_radius="100dp"
+                android:src="@color/colorAccent"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+
+            <TextView
+                android:textSize="30sp"
+                android:text="2"
+                android:textColor="@color/colorWhite"
+                android:gravity="center"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+        </RelativeLayout>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_3"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        android:layout_marginLeft="300dp"
+        android:layout_width="100dp"
+        android:layout_height="100dp">
+
+        <RelativeLayout
+            android:id="@+id/view3"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <com.xuexiang.xui.widget.imageview.RadiusImageView
+                app:riv_corner_radius="100dp"
+                android:src="@color/colorAccent"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+
+            <TextView
+                android:textSize="30sp"
+                android:text="3"
+                android:textColor="@color/colorWhite"
+                android:gravity="center"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+        </RelativeLayout>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_4"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        android:layout_marginLeft="400dp"
+        android:layout_width="100dp"
+        android:layout_height="100dp">
+
+        <RelativeLayout
+            android:id="@+id/view4"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <com.xuexiang.xui.widget.imageview.RadiusImageView
+                app:riv_corner_radius="100dp"
+                android:src="@color/colorAccent"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+
+            <TextView
+                android:textSize="30sp"
+                android:text="4"
+                android:textColor="@color/colorWhite"
+                android:gravity="center"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+        </RelativeLayout>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_5"
+        app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        android:layout_marginLeft="500dp"
+        android:layout_width="100dp"
+        android:layout_height="100dp">
+
+        <RelativeLayout
+            android:id="@+id/view5"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <com.xuexiang.xui.widget.imageview.RadiusImageView
+                app:riv_corner_radius="100dp"
+                android:src="@color/colorAccent"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+
+            <TextView
+                android:textSize="30sp"
+                android:text="5"
+                android:textColor="@color/colorWhite"
+                android:gravity="center"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"/>
+        </RelativeLayout>
+
+    </RelativeLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>