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;
}
}); }
}
OnTouchListener的更多相关文章
- android 事件分发机制详解(OnTouchListener,OnClick)
昨天做东西做到触摸事件冲突,以前也经常碰到事件冲突,想到要研究一下Android的事件冲突机制,于是从昨天开始到今天整整一天时间都要了解这方面的知识,这才懂了安卓的触摸和点击事件的机制.探究如下: 首 ...
- android OnTouchListener 按下与抬起
写法一: private OnTouchListener pressOnTouchListener = new OnTouchListener(){ @Override public boolean ...
- Android OnTouchListener,OnClickListener和OnLongClickListener的关系
在OnTouchListener事件里有MotionEvent.ACTION_DOWN,MotionEvent.ACTION_UP和MotionEvent.ACTION_MOVE三个事件,我们在这里只 ...
- onTouch事件试验(覆写onTouchEvent方法,同时设置onTouchListener)
xml布局文件 <</span>RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andro ...
- Android Touch(2)View.OnTouchEvent与View.OnTouchListener区别
1,在官方文档 docs/reference/android/view/View.OnTouchListener.html 中对OnTouchListener的描述 Interface definit ...
- OnTouchListener事件监听实现方式之GestureDetector
当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等. 一般情况下,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouc ...
- 为EditText设置OnTouchListener事件监听
在项目中需要在EditText输入前,判断某个值是否已经有值,有才可以输入,为NULL值则提示不让输入,先填写指定的编辑框 自己试过监听获取焦点事件,来设置setFocusable(true)或者se ...
- android 页面滑动 ViewFlipper,OnGestureListener,OnTouchListener
public class Main extends Activity implements OnGestureListener, OnTouchListener { // 一般不直接使用ViewAni ...
- ImageView 设置OnTouchListener
ImageView的OnTouchListener,onTouch方法要返回true,MotionEvent.ACTION_UP,MotionEvent.ACTION_MOVE 才有效. 其实关于返回 ...
- ImageView 会盖掉ScrollView的OnTouchListener,监听Activity的手势
当Activity的高度不够滑动的时候,ImageView会盖掉ScrollView的OnTouchListener监听. 这个时候须要设置Activity的(或者想直接监听Activity的手势也能 ...
随机推荐
- vijos1083:小白逛公园
小白逛公园 描述 小新经常陪小白去公园玩,也就是所谓的遛狗啦…在小新家附近有一条“公园路”,路的一边从南到北依次排着n个公园,小白早就看花了眼,自己也不清楚该去哪些公园玩了. 一开始,小白就根据公园的 ...
- Google Authenticator(谷歌身份验证器)C#版
摘要:Google Authenticator(谷歌身份验证器),是谷歌公司推出的一款动态令牌工具,解决账户使用时遭到的一些不安全的操作进行的"二次验证",认证器基于RFC文档中的 ...
- 二叉树遍历(Java实现)
二叉树遍历(Java实现) 主要是二叉树的遍历,包括递归遍历和非递归遍历 import java.util.ArrayDeque; import java.util.ArrayList; impo ...
- 如何在win7下安装python包工具pip
1. 在安装pip前,请确认你win系统中已经安装好了python,和easy_install工具,如果系统安装成功,easy_install在目录C:\Python27\Scripts 下面, 确认 ...
- WordPress 通过文章 URL 获取文章 ID
// 获取当前文章链接,注意,在文章类型页面的主循环外使用标签时,如果没有指定 Post ID 参数,该标签将返回循环中最后一篇文章的 URL,而不是当前页面的固定链接,或者直接不返回结果,所以一般需 ...
- 菜鸟之路——机器学习之非线性回归个人理解及python实现
关键词: 梯度下降:就是让数据顺着梯度最大的方向,也就是函数导数最大的放下下降,使其快速的接近结果. Cost函数等公式太长,不在这打了.网上多得是. 这个非线性回归说白了就是缩小版的神经网络. py ...
- 通过sql查询rman备份信息
通过sql查询rman备份信息 查看所有备份集 SELECT A.RECID "BACKUP SET", A.SET_STAMP, DECODE (B.INCREMENTAL_LE ...
- vue中scoped vs css modules
注意:此文是默认你已经具备scoped和css modules的相关基础知识,所以不做用法上的讲解. 在vue中,我们有两种方式可以定义css作用域,一种是scoped,另一种就是css module ...
- leetcode 21 list merge
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...
- MFC点击控件拖动窗口
void CMouseClickDlg::OnLButtonDown(UINT nFlags, CPoint point) { CDialogEx::OnLButtonDown(nFlags, poi ...