Utilizzo la libreria PhotoView, tuttavia quando la utilizzo con viewpager viene visualizzato un errore durante lo zoom.ArrayIndexOutOfBoundsException in PhotoView + ViewPager
08-22 17:14:50.096: E/AndroidRuntime(8740): FATAL EXCEPTION: main
08-22 17:14:50.096: E/AndroidRuntime(8740): java.lang.IllegalArgumentException: pointerIndex out of range
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.MotionEvent.nativeGetAxisValue(Native Method)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.MotionEvent.getX(MotionEvent.java:2148)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1834)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1909)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
08-22 17:14:50.096: E/AndroidRuntime(8740): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2182)
08-22 17:14:50.096: E/AndroidRuntime(8740): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1512)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
08-22 17:14:50.096: E/AndroidRuntime(8740): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2130)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.View.dispatchPointerEvent(View.java:7641)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3613)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4804)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4783)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4875)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:174)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4854)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4894)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.Choreographer.doFrame(Choreographer.java:530)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.os.Handler.handleCallback(Handler.java:725)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.os.Handler.dispatchMessage(Handler.java:92)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.os.Looper.loop(Looper.java:137)
08-22 17:14:50.096: E/AndroidRuntime(8740): at android.app.ActivityThread.main(ActivityThread.java:5328)
08-22 17:14:50.096: E/AndroidRuntime(8740): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 17:14:50.096: E/AndroidRuntime(8740): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 17:14:50.096: E/AndroidRuntime(8740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-22 17:14:50.096: E/AndroidRuntime(8740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
08-22 17:14:50.096: E/AndroidRuntime(8740): at dalvik.system.NativeStart.main(Native Method)
08-22 17:15:18.416: D/dalvikvm(8872): GC_FOR_ALLOC freed 94K, 14% free 17782K/20656K, paused 13ms, total 13ms
Anche se, lo zoom funziona alla grande, ma quando l'immagine diventano di gran lunga, quindi si verifica l'errore e la mia attività incidente .. Ecco i miei codici in viewapager:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
pv = new PhotoView(getActivity());
pv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
imageLoader.DisplayImage(mContent, pv);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(pv);
return layout;
}
Googled il problema, ma non puà ² trovare una soluzione adeguata! qualche suggerimento?? Grazie ragazzi
tutta la mia codici:
public class viewpager extends SherlockFragmentActivity {
AllPhonesDatabase apd;
Bundle gotBasket;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.simple_circles);
apd = new AllPhonesDatabase(this.getApplicationContext()).open();
gotBasket = viewpager.this.getIntent().getExtras();
final String imageurl1 = gotBasket.getString("Imageurl1");
final String imageurl2 = gotBasket.getString("Imageurl2");
final String imageurl3 = gotBasket.getString("Imageurl3");
TestFragmentAdapter mAdapter = new TestFragmentAdapter(
this.getSupportFragmentManager(), imageurl1, imageurl2,
imageurl3);
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
CirclePageIndicator mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
}
class TestFragmentAdapter extends FragmentPagerAdapter {
protected static String[] CONTENT;
private int mCount;
public TestFragmentAdapter(FragmentManager fm, String imageurl1,
String imageurl2, String imageurl3) {
super(fm);
CONTENT = new String[] { imageurl1, imageurl2, imageurl3 };
mCount = CONTENT.length;
}
@Override
public Fragment getItem(int position) {
return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
}
@Override
public int getCount() {
return mCount;
}
@Override
public CharSequence getPageTitle(int position) {
return TestFragmentAdapter.CONTENT[position % CONTENT.length];
}
public void setCount(int count) {
if (count > 0 && count <= 10) {
mCount = count;
notifyDataSetChanged();
}
}
public final class TestFragment extends Fragment {
private static final String KEY_CONTENT = "TestFragment:Content";
public ImageLoader2 imageLoader;
PhotoView pv;
public static TestFragment newInstance(String content) {
TestFragment fragment = new TestFragment();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 1; i++) {
builder.append(content).append(" ");
}
builder.deleteCharAt(builder.length() - 1);
fragment.mContent = builder.toString();
return fragment;
}
private String mContent = "???";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imageLoader = new com.androidarabia.lazylist.ImageLoader2(
this.getActivity());
if ((savedInstanceState != null)
&& savedInstanceState.containsKey(KEY_CONTENT)) {
mContent = savedInstanceState.getString(KEY_CONTENT);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
pv = new PhotoView(getActivity());
pv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
imageLoader.DisplayImage(mContent, pv);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(pv);
return layout;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_CONTENT, mContent);
}
Grazie per la tua risposta! Dove posso aggiungere questo codice nella mia applicazione? –
ho aggiornato i miei codici. Puoi dirmi dove posso aggiungerlo ora? –
Ovunque tu dichiari il tuo ViewPager, invece usi HackyViewPager –