Help us understand the problem. What is going on with this article?

kotlinでandroidのtextdrag

More than 3 years have passed since last update.

概要

TextViewを長押しでドラッグする

MainActivity.kt
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.view.View

class MainActivity : AppCompatActivity() , View.OnLongClickListener {
    lateinit var  vi : View
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        vi = findViewById(R.id.text)
        vi.setOnLongClickListener(this)
    }
    @RequiresApi(Build.VERSION_CODES.N)
    override  fun onLongClick(v : View): Boolean {
        v.startDrag(null, View.DragShadowBuilder(v), v, 2)
        return true;
    }
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.nimani.drag.MainActivity">

    <TextView
        android:id="@+id/text"
        android:layout_width="121dp"
        android:layout_height="66dp"
        android:text="Hello World!"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="109dp" />

</android.support.constraint.ConstraintLayout>

それだけ

nimani76
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away