解决方案 »
- 不显示删除回复显示所有回复显示星级回复显示得分回复 ●●●小白求助 关于创建Android应用的问题
- 【转】Android permission 访问权限大全
- android程序自动更新安装详解.doc
- ListView 焦点移动
- 怎么设置layout的宽和高相等,要动态的
- 如何让音乐播放10s停10s再播放10s循环下去?
- 多个Toast同时显示时,希望同时显示在屏幕而不是依次显示,怎么办?
- 请教一个android调用JS的问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 菜鸟求救 安卓http请求乱码问题
- 谁有《大话企业级Android应用开发实战》(王家林)第六章的代码?发到我:一丝一一二八五灵司令QQ邮箱
- android for C++ndk调用接口函数adk停止运行//接口函数的格式是什么?
- 请问关于TextView的问题
public static final String Tag = "CreatView";
private Context mContext;
protected static CreatView mCreatView;
private int[] location;
public ImageView mImageView;
public ImageView mImageView1;
public ImageView mImageView2;
public ImageView mImageView3;
public WindowManager mWm;
public WindowManager.LayoutParams layoutParams;
public CreatView(Context context) {
this.mContext = context;
mWm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
layoutParams = new WindowManager.LayoutParams();
}
public synchronized static CreatView getCreatView(Context context) {
Log.d(Tag, "getCreatView");
if (mCreatView == null) {
mCreatView = new CreatView(context);
}
return mCreatView;
}
public void setLocation(int[] location) {
this.location = location;
}
private View createNewView() {
Log.d(Tag, "createNewView");
ImageView mImageView = new ImageView(mContext);
mImageView.setImageDrawable(mContext.getResources().getDrawable(
R.drawable.apple));
mImageView.setLayoutParams(new LinearLayout.LayoutParams(40, 40));
return mImageView;
}
public void addViewToScreen() {
Log.d(Tag, "addViewToScreen");
mImageView = (ImageView)createNewView();
mImageView1 = (ImageView)createNewView();
mImageView2 = (ImageView)createNewView();
mImageView3 = (ImageView)createNewView();
mImageView.setOnTouchListener(new TouchListener());
mImageView1.setOnTouchListener(new TouchListener());
mImageView2.setOnTouchListener(new TouchListener());
mImageView3.setOnTouchListener(new TouchListener());
layoutParams.gravity = Gravity.LEFT | Gravity.TOP;
layoutParams.x = location[0] + 30; //偏移量x
layoutParams.y = location[1]; //偏移量y
layoutParams.width = 40;
layoutParams.height = 40;
layoutParams.alpha = 1.0f;
mWm.addView(mImageView, layoutParams);
mWm.addView(mImageView1, layoutParams);
mWm.addView(mImageView2, layoutParams);
mWm.addView(mImageView3, layoutParams);
}
class TouchListener implements OnTouchListener {
int lastX;
int lastY;
int screenWidth;
int screenHeight;
public TouchListener() {
DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels;
Log.d(Tag, "screen width =" + screenWidth + ",screen height="
+ screenHeight);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(Tag, "TouchListener -- onTouch");
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = (int) event.getRawX();
lastY = (int) event.getRawY();
Log.d(Tag, "down x=" + lastX + ", y=" + lastY);
break;
case MotionEvent.ACTION_MOVE:
int dx = (int) event.getRawX() - lastX;
int dy = (int) event.getRawY() - lastY;
Log.d(Tag, "move dx=" + dx + ", dy=" + dy);
int left = v.getLeft() + dx;
int top = v.getTop() + dy;
int right = v.getRight() + dx;
int bottom = v.getBottom() + dy;
Log.d(Tag, "view left=" + left + ", top=" + top + ", right="
+ right + ",bottom=" + bottom);
// set bound
if (left < 0) {
left = 0;
right = left + v.getWidth();
}
if (right > screenWidth) {
right = screenWidth;
left = right - v.getWidth();
}
if (top < 0) {
top = 0;
bottom = top + v.getHeight();
}
if (bottom > screenHeight) {
bottom = screenHeight;
top = bottom - v.getHeight();
}
v.layout(left, top, right, bottom);
lastX = (int) event.getRawX();
lastY = (int) event.getRawY();
layoutParams.x = lastX;
layoutParams.y = lastY-30;
mWm.updateViewLayout(v, layoutParams);
lastX = (int) event.getRawX();
lastY = (int) event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
}
}
代码在这里了,目前就是只能移动那个中间的view,是不是要设置监听范围?