概述
xlistview监听 xlistview.setOnItemClickListener(this); return convertView; } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 创建集合把图片发送到下一个界面 final ArrayList<String> str=new ArrayList<String>(); str.add(list.get(position-1).getThumbnail_pic_s()); str.add(list.get(position-1).getThumbnail_pic_s02()); str.add(list.get(position-1).getThumbnail_pic_s03()); Intent intent=new Intent(getActivity(),PhotoActivity.class); intent.putStringArrayListExtra("txt",str); startActivity(intent); } 第二个界面实现放大缩小public class PhotoActivity extends AppCompatActivity { private HackyViewPager viewpager; private ArrayList<String> txt; private ArrayList<View> list = new ArrayList<>(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pic); viewpager = (HackyViewPager) findViewById(R.id.viewpager1); Intent intent = getIntent(); txt = intent.getStringArrayListExtra("txt"); ImageOptions options=new ImageOptions.Builder() .setUseMemCache(true) .setSize(200,200) .build(); PhotoView photoView=new PhotoView(PhotoActivity.this); x.image().bind(photoView,txt.get(0),options); PhotoView photoView1=new PhotoView(PhotoActivity.this); x.image().bind(photoView1,txt.get(1),options); PhotoView photoView2=new PhotoView(PhotoActivity.this); x.image().bind(photoView2,txt.get(2),options); list.add(photoView); list.add(photoView1); list.add(photoView2); myadapter adapter=new myadapter(); viewpager.setAdapter(adapter); } class myadapter extends PagerAdapter{ @Override public int getCount() { return list.size(); } @Override public boolean isViewFromObject(View view, Object object) { return view==object; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(list.get(position)); } @Override public Object instantiateItem(ViewGroup container, int position) { container.addView(list.get(position)); return list.get(position); } } } 继承Viewpagerpublic class PhotoViewpager extends ViewPager { public PhotoViewpager(Context context) { super(context); } public PhotoViewpager(Context context, AttributeSet attrs) { super(context, attrs); } //重写该方法来解决冲突问题 test.bawei.com.tupianosuofang.PhotoViewPager(自定义布局的全名自己//类的名字) @Override public boolean onInterceptHoverEvent(MotionEvent event) { try { return super.onInterceptHoverEvent(event); }catch (IllegalFormatCodePointException e){ e.printStackTrace(); Log.e("TAG", "onInterceptTouchEvent: " ); return false; } } }布局<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <cn.bluemobi.dylan.photoview.HackyViewPager android:id="@+id/viewpager1" android:layout_width="300dp" android:layout_height="200dp"> </cn.bluemobi.dylan.photoview.HackyViewPager> </LinearLayout>需要导photoview包
最后
以上就是现实母鸡为你收集整理的viewpager实现图片放大缩小的全部内容,希望文章能够帮你解决viewpager实现图片放大缩小所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复