Back to project page TouchImageView.
The source code is released under:
opyright (c) 2012 Michael Ortiz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softw...
If you think the Android project TouchImageView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.ortiz.touch; /* w w w . ja v a 2s .c om*/ import com.example.touch.R; import android.app.Activity; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; public class ViewPagerExampleActivity extends Activity { /** * Step 1: Download and set up v4 support library: http://developer.android.com/tools/support-library/setup.html * Step 2: Create ExtendedViewPager wrapper which calls TouchImageView.canScrollHorizontallyFroyo * Step 3: ExtendedViewPager is a custom view and must be referred to by its full package name in XML * Step 4: Write TouchImageAdapter, located below * Step 5. The ViewPager in the XML should be ExtendedViewPager */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_viewpager_example); ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new TouchImageAdapter()); } static class TouchImageAdapter extends PagerAdapter { private static int[] images = { R.drawable.nature_1, R.drawable.nature_2, R.drawable.nature_3, R.drawable.nature_4, R.drawable.nature_5 }; @Override public int getCount() { return images.length; } @Override public View instantiateItem(ViewGroup container, int position) { TouchImageView img = new TouchImageView(container.getContext()); img.setImageResource(images[position]); container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); return img; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } } }