android中超过屏幕大小的图片的拖动

java代码:

package com.cndemo;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MotionEvent;import android.view.View;import android.widget.ImageView;public class MainActivity extends Activity {private float mx;private float my;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);super.onCreate(savedInstanceState);final ImageView switcherView = (ImageView) this.findViewById(R.id.img);switcherView.setOnTouchListener(new View.OnTouchListener() {public boolean onTouch(View arg0, MotionEvent event) {float curX, curY;switch (event.getAction()) {case MotionEvent.ACTION_DOWN:mx = event.getX();my = event.getY();break;case MotionEvent.ACTION_MOVE:curX = event.getX();curY = event.getY();switcherView.scrollBy((int) (mx - curX), (int) (my - curY));mx = curX;my = curY;break;case MotionEvent.ACTION_UP:curX = event.getX();curY = event.getY();switcherView.scrollBy((int) (mx - curX), (int) (my - curY));break;}return true;}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_main, menu);return true;}}

页面布局代码:

<RelativeLayout 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" >    <ImageView        android:id="@+id/img"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:scaleType="center"        android:src="@drawable/img8" /></RelativeLayout>


更多相关文章

  1. android 拖动图片移动效果
  2. 记录代码合并时产生的bug
  3. Android获取屏幕分辨率
  4. Android(安卓)获得屏幕大小
  5. Android(安卓)用源代码写layout布局
  6. android截取屏幕图片
  7. Eclipse 开发 Android, Hello FormStuff(学习9)
  8. Android(安卓)开发常用代码片段
  9. Android常用功能代码块

随机推荐

  1. Android中TextView文字居中与垂直靠左居
  2. C#开发Android手机应用全接触(mono for a
  3. 为Android内核添加新驱动,并添加到menucon
  4. 修改android 睡眠的时间的两种方法
  5. android基础知识15:获得android系统信息01
  6. android获取系统标准时区的时间
  7. Android特效第四篇:Android抽屉实现
  8. Android设置颜色的几种方法
  9. android:versionCode和android:versionNa
  10. 【Android】滚动条属性