我正在尝试从这里的一个示例进行ontouch图像缩放并触摸移动屏幕缩小的其他部分,所以我找到了这个链接并尝试在代码中实现,但是有一些错误,比如
04-06 10:58:53.618: ERROR/AndroidRuntime(493): FATAL EXCEPTION: main
04-06 10:58:53.618: ERROR/AndroidRuntime(493): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Zoom_imageview/com.Zoom_imageview.Zoom_imageviewActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class com.sonyericsson.zoom.ImageZoomView
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.os.Handler.dispatchMessage(Handler.java:99)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.os.Looper.loop(Looper.java:123)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at java.lang.reflect.Method.invoke(Method.java:521)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at dalvik.system.NativeStart.main(Native Method)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.sonyericsson.zoom.ImageZoomView
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.Activity.setContentView(Activity.java:1647)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at com.Zoom_imageview.Zoom_imageviewActivity.onCreate(Zoom_imageviewActivity.java:38)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-06 10:58:53.618: ERROR/AndroidRuntime(493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
代码 :
package com.Zoom_imageview;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.Zoom_imageview.zoom.ImageZoomView;
import com.Zoom_imageview.zoom.SimpleZoomListener;
import com.Zoom_imageview.zoom.ZoomState;
import com.Zoom_imageview.zoom.SimpleZoomListener.ControlType;
public class Zoom_imageviewActivity extends Activity {
/** Called when the activity is first created. */
private static final int MENU_ID_ZOOM = 0;
/** Constant used as menu item id for setting pan control type */
private static final int MENU_ID_PAN = 1;
/** Constant used as menu item id for resetting zoom state */
private static final int MENU_ID_RESET = 2;
/** Image zoom view */
private ImageZoomView mZoomView;
/** Zoom state */
private ZoomState mZoomState;
/** Decoded bitmap image */
private Bitmap mBitmap;
private SimpleZoomListener mZoomListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
mZoomState = new ZoomState();
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
mZoomListener = new SimpleZoomListener();
mZoomListener.setZoomState(mZoomState);
mZoomView = (ImageZoomView)findViewById(R.id.zoomview);
mZoomView.setZoomState(mZoomState);
mZoomView.setImage(mBitmap);
mZoomView.setOnTouchListener(mZoomListener);
resetZoomState();
}catch (Exception e) {
// TODO: handle exception
}
}
@Override
protected void onDestroy() {
super.onDestroy();
mBitmap.recycle();
mZoomView.setOnTouchListener(null);
mZoomState.deleteObservers();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, MENU_ID_ZOOM, 0, R.string.menu_zoom);
menu.add(Menu.NONE, MENU_ID_PAN, 1, R.string.menu_pan);
menu.add(Menu.NONE, MENU_ID_RESET, 2, R.string.menu_reset);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_ID_ZOOM:
mZoomListener.setControlType(ControlType.ZOOM);
break;
case MENU_ID_PAN:
mZoomListener.setControlType(ControlType.PAN);
break;
case MENU_ID_RESET:
resetZoomState();
break;
}
return super.onOptionsItemSelected(item);
}
/**
* Reset zoom state and notify observers
*/
private void resetZoomState() {
mZoomState.setPanX(0.5f);
mZoomState.setPanY(0.5f);
mZoomState.setZoom(1f);
mZoomState.notifyObservers();
}
}
XML ::
<?xml version="1.0" encoding="utf-8"?>
<com.sonyericsson.zoom.ImageZoomView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/zoomview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
请帮帮我...