以下是我的代码
package com.staticwallpapercustomview;import android.os.Bundle;
import android.app.Activity;
import android.widget.ImageView;public class CustomViewActivity extends Activity { private float mx ;
private ImageView imgWallpaper;
private Bitmap bitmap; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_static_wall_paper);
setupView(); }
private OnTouchListener touchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
float curX;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
break;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
imgWallpaper.scrollBy((int) (mx - curX), 0);
mx = curX;
break;
case MotionEvent.ACTION_UP:
//imgWallpaper.beginMove();
break;
}
return true;
}
};
public void setupView(){
imgWallpaper = (ImageCustomView) this.findViewById(R.id.img_wallpaper);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a1);
imgWallpaper.setImageBitmap(bitmap);
imgWallpaper.setOnTouchListener(touchListener);
}
}只要把ImageView的scaleType设为center就可以运行此程序了,但是滑动图片会超边边界,出现白边,还请大神们帮忙为我解决滑动超过图片边界的问题,谢谢了
package com.staticwallpapercustomview;import android.os.Bundle;
import android.app.Activity;
import android.widget.ImageView;public class CustomViewActivity extends Activity { private float mx ;
private ImageView imgWallpaper;
private Bitmap bitmap; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_static_wall_paper);
setupView(); }
private OnTouchListener touchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
float curX;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
break;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
imgWallpaper.scrollBy((int) (mx - curX), 0);
mx = curX;
break;
case MotionEvent.ACTION_UP:
//imgWallpaper.beginMove();
break;
}
return true;
}
};
public void setupView(){
imgWallpaper = (ImageCustomView) this.findViewById(R.id.img_wallpaper);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a1);
imgWallpaper.setImageBitmap(bitmap);
imgWallpaper.setOnTouchListener(touchListener);
}
}只要把ImageView的scaleType设为center就可以运行此程序了,但是滑动图片会超边边界,出现白边,还请大神们帮忙为我解决滑动超过图片边界的问题,谢谢了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货