zoukankan      html  css  js  c++  java
  • OnTouchListener

    1.布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
        android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:orientation="vertical"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="helloworld.com.inspur.app4.MainActivity">
    
        <TextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hah"
            android:id="@+id/tv_1"
            />
        <TextView android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="hahahh"
            android:id="@+id/tv_2"
             />
    </LinearLayout>

    (2)逻辑代码的实现

    package helloworld.com.inspur.app4;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
        private TextView tv1;
        private TextView tv2;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv1=(TextView)findViewById(R.id.tv_1);
            tv2=(TextView)findViewById(R.id.tv_2);
            tv2.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                   switch (event.getAction())
                    {
                        case MotionEvent.ACTION_UP:
                            Toast.makeText(MainActivity.this,"按下",Toast.LENGTH_SHORT).show();
                            break;
                        case MotionEvent.ACTION_MOVE:
                            Toast.makeText(MainActivity.this,"移动",Toast.LENGTH_SHORT).show();
                            break;
                        case MotionEvent.ACTION_DOWN:
                            Toast.makeText(MainActivity.this,"松开",Toast.LENGTH_SHORT).show();
                            break;
                    }
    
    
                    return true;
                }
            });
    
        }
    }
  • 相关阅读:
    python 线程Queue 用法代码展示
    Python中的join()函数的用法
    python 中爬虫 content和text的区别
    免费代理ip爬虫分享
    django数据库的表已迁移的不能重新迁移的解决办法
    RuntimeError: Model class app_anme.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.---python学习错误记录
    MYSQL查询操作 详细
    mysql数据库的基本操作命令总结
    http短连接与长连接简介
    浅谈http协议
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9007968.html
Copyright © 2011-2022 走看看