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;
}
}); }
}

OnTouchListener的更多相关文章

  1. android 事件分发机制详解(OnTouchListener,OnClick)

    昨天做东西做到触摸事件冲突,以前也经常碰到事件冲突,想到要研究一下Android的事件冲突机制,于是从昨天开始到今天整整一天时间都要了解这方面的知识,这才懂了安卓的触摸和点击事件的机制.探究如下: 首 ...

  2. android OnTouchListener 按下与抬起

    写法一: private OnTouchListener pressOnTouchListener = new OnTouchListener(){ @Override public boolean ...

  3. Android OnTouchListener,OnClickListener和OnLongClickListener的关系

    在OnTouchListener事件里有MotionEvent.ACTION_DOWN,MotionEvent.ACTION_UP和MotionEvent.ACTION_MOVE三个事件,我们在这里只 ...

  4. onTouch事件试验(覆写onTouchEvent方法,同时设置onTouchListener)

    xml布局文件 <</span>RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andro ...

  5. Android Touch(2)View.OnTouchEvent与View.OnTouchListener区别

    1,在官方文档 docs/reference/android/view/View.OnTouchListener.html 中对OnTouchListener的描述 Interface definit ...

  6. OnTouchListener事件监听实现方式之GestureDetector

    当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等. 一般情况下,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouc ...

  7. 为EditText设置OnTouchListener事件监听

    在项目中需要在EditText输入前,判断某个值是否已经有值,有才可以输入,为NULL值则提示不让输入,先填写指定的编辑框 自己试过监听获取焦点事件,来设置setFocusable(true)或者se ...

  8. android 页面滑动 ViewFlipper,OnGestureListener,OnTouchListener

    public class Main extends Activity implements OnGestureListener, OnTouchListener { // 一般不直接使用ViewAni ...

  9. ImageView 设置OnTouchListener

    ImageView的OnTouchListener,onTouch方法要返回true,MotionEvent.ACTION_UP,MotionEvent.ACTION_MOVE 才有效. 其实关于返回 ...

  10. ImageView 会盖掉ScrollView的OnTouchListener,监听Activity的手势

    当Activity的高度不够滑动的时候,ImageView会盖掉ScrollView的OnTouchListener监听. 这个时候须要设置Activity的(或者想直接监听Activity的手势也能 ...

随机推荐

  1. MapReduce实现单词统计

     开发工具:IDEA mapreduce实现思路: Map阶段: a) 从HDFS的源数据文件中逐行读取数据 b) 将每一行数据切分出单词 c) 为每一个单词构造一个键值对(单词,1) d) 将键值对 ...

  2. Django权限管理系统设计分析

    权限管理顾名思义,其实就是角色控制权限的系统,每个用户对应一个角色,每个角色有对应的权限,比如公司会有CEO,总监,销售经理,销售员,每个人的权限都不一样,那我们给他展示的url也都不同 一.首先创建 ...

  3. 性能测试工具—Jmeter

    Jmeter视频教程: 在我要自学网搜索:关键字即可

  4. 用nc+简单bat/vbs脚本+winrar制作迷你远控后门

    前言 某大佬某天和我聊起了nc,并且提到了nc正反向shell这个概念. 我对nc之前的了解程度仅局限于:可以侦听TCP/UDP端口,发起对应的连接. 真正的远控还没实践过,所以决定写个小后门试一试. ...

  5. manjaro安装anaconda出错

    出错信息: ==> Creating package "anaconda"...  -> Generating .PKGINFO file...  -> Gene ...

  6. [oldboy-django][2深入django]rest-framework教程

    # rest-framework教程 - settings.py INSTALL-APPS = [ 'snippets', # app 'rest-framework', ] - 创建model # ...

  7. Log4j官方文档翻译(五、日志输出的方法)

    日志类提供了很多方法用于处理日志活动,它不允许我们自己实例化一个logger,但是提供给我们两种静态方法获得logger对象: public static Logger getRootLogger() ...

  8. 【翻译】Apache软件基金会1

    最近有点看不进去书,所以就找点东西翻译下,正好很想了解Apache基金会都有什么开源项目,每天找点事时间翻译翻译,还可以扩展下视野. 今天就看了两个,第一个是关于.NET的,不再兴趣范围内.第二个还挺 ...

  9. ELF反调试初探

    ELF反调试初探 http://www.freebuf.com/sectool/83509.html ELF(Executable and Linkable Format)是Unix及类Unix系统下 ...

  10. codevs 1380/HDU 1520 树形dp

    1380 没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 回到问题 题目描述 Description Ural大学有N个职员 ...