本文介绍了缩放具有onTouch Android效果的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在此用于ontouch图像缩放和触摸移动屏幕缩小的其他部分,因此我只是找到了此链接并尝试在代码中实现,但是出现类似
i am trying one example from Here for ontouch image zoom and touch on other section of mobile screen zoom-out so simply i have find this link and try to implement in code but there are something error like
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"
/>
请帮帮我...
推荐答案
<?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"
/>
将其更改为
<?xml version="1.0" encoding="utf-8"?>
<com.Zoom_imageview.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"
/>
或如果您尚未在项目中添加ImageZoomView类,则请按示例此处
or if u have not added a class ImageZoomView in your project then plz add it as in example Here
这篇关于缩放具有onTouch Android效果的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!