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. python中pip 出错

    错误:error in launcher: Unable to create process using '" python多个版本时出现, 解决方法-- 将pip重新安装 python3 ...

  2. 【MySQL】资源列表

    1.使用yum方式安装MySQL https://blog.csdn.net/zl570932980/article/details/78934601 2.安装Xtrabackup备份工具 https ...

  3. ECharts的x轴和y轴均使用数值类型

    今天有个需求,就是需要ECharts的x轴和y轴都要使用数值类型,即xAxis.type和yAxis.type均为value,然后我按照我以为的方式修改了下,发现图崩了 发现问题: 然后我打开了ECh ...

  4. 谋哥:App推广最有效的是自推广

    [谋哥每天一原创,第一百五十二篇] 目前市场上,各类App已经覆盖到所有你能想到的领域,并且各个山头也被占得差不多了,网上 的说法就是布局已经完成.如果你想现在再插那么一杠子进去,就得看你的真本事了, ...

  5. 设计模式之第4章-装饰模式(Java实现)

    设计模式之第4章-装饰模式(Java实现) “怎么了,鱼哥?” “唉,别提了,网购了一件衣服,结果发现和商家描述的差太多了,有色差就算了,质量还不好,质量不好就算了,竟然大小也不行,说好的3个X,邮的 ...

  6. 嵌入式之download

    ISP ISP(In-System Programming)在系统可编程,指电路板上的空白器件可以编程写入最终用户代码, 而不需要从电路板上取下器件,已经编程的器件也可以用ISP方式擦除或再编程.IS ...

  7. Monkey官方帮助翻译&介绍

    都说想学好就看原文,英文不好为了翻译这个可费了大劲了.表格从GOOGLE官网复制到WORD里编辑,结果贴上来格式全乱了,只得不弄表格了.表格中官网的事件不是最新的,比最新的少2个,具体我会另发一篇文章 ...

  8. PHP 获取客户端用户 IP 地址

    一般情况下可以使用以下代码获取到用户 IP 地址 echo 'User IP - '.$_SERVER['REMOTE_ADDR']; // 服务器在局域网的话,那么显示的则是内网IP .// 如果服 ...

  9. [oldboy-django][5python基础][高级特性]Iterator迭代器

    # 区分可迭代对象iterable, 迭代器iterator, 生成器generator a. iterable 可直接用for循环的对象,都称为可迭代对象, from collections imp ...

  10. C++字符串高效查找替换,有空分析分析

    void CWebTransfer::Substitute(char *pInput, char *pOutput, char *pSrc, char *pDst) { char *pi, *po, ...