下面是我的xml文档。 该名称为主。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/imageView" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/icon"
android:scaleType="matrix">
</ImageView>
<ImageView android:id="@+id/imageView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:src="@drawable/bg_sound"
android:scaleType="matrix"></ImageView>
</FrameLayout>
And My Java 档案如下:
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
public class Test1Activity extends Activity implements OnTouchListener {
private static final String TAG = "Touch";
// These matrices will be used to move and zoom image
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
// We can be in one of these 3 states
// Remember some things for zooming
PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView view = (ImageView) findViewById(R.id.imageView);
view.setOnTouchListener(this);
ImageView view1 = (ImageView) findViewById(R.id.imageView1);
view1.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
// Dump touch event to log
// Handle touch events here...
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
savedMatrix.set(matrix);
start.set(event.getX(), event.getY());
break;
case MotionEvent.ACTION_UP:
savedMatrix.set(matrix);
//matrix.postRotate(90);
break;
case MotionEvent.ACTION_MOVE:
// ...
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY()
- start.y);
break;
}
view.setImageMatrix(matrix);
view.invalidate();
return true; // indicate event was handled
}
}
I am able to achieve move on touch but as there are 2 imageviews added only latest added imageviews is movable.
I guess problem is layout_width="liver_other"
, which causes only front cultureview to be recognized onpass. 如果我使用<代码>layout_width=“wrap_content”,则光是图像调查在该图像区移动,而且看不见。
如何解决这一问题?
感谢