我需要使ImageView消失。我该怎么做?这是我需要做的最后一个。 我有纸。我需要将它移到篮子里,它会消失。
Main5Activity.kt 我意识到文件移动了。如何实现删除碎片或消失?
package com.example.fairytale_quest
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.MotionEvent
import android.view.View
import kotlinx.android.synthetic.main.activity_main5.*
class Main5Activity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main5)
val actionBar = supportActionBar
actionBar!!.hide()
var listener = View.OnTouchListener(function = { view, motionEvent ->
if (motionEvent.action == MotionEvent.ACTION_MOVE) {
view.y = motionEvent.rawY - view.height/2
view.x = motionEvent.rawX - view.width/2
}
true
})
draggableImage.setOnTouchListener(listener)
}
}
带有纸张和废纸pie的xml文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main5Activity">
<ImageView
android:layout_width="128dp"
android:layout_height="140dp" app:srcCompat="@drawable/pop"
android:id="@+id/draggableImage" android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" android:contentDescription="draggable"/>
<ImageView
android:src="@drawable/basketwaste"
android:layout_width="96dp"
android:layout_height="121dp"
android:id="@+id/imageView2" android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp" android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="0.026" android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0"/>
</android.support.constraint.ConstraintLayout>