之前已经学过了ExpandableListView的基本用法,这次就在上面的基础上来结合PhotoView实现真正的浏览图片的做法。
使用PhotoView前需要添加依赖:
compile 'com.github.chrisbanes.photoview:library:1.2.4'
然后创建WatchPicturesActivity活动,它的布局是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/vp_all_pictures"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
然后WatchPicturesActivity的具体代码是:
public class WatchPicturesActivity extends AppCompatActivity {
private AllPictureBean.ShowapiResBodyBean.PagebeanBean.ContentlistBean picturesBean;
private ViewPager vp_all_pictures;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_watch_pictures);
picturesBean = (AllPictureBean.ShowapiResBodyBean.PagebeanBean.ContentlistBean) getIntent().getSerializableExtra("picturesBean");
initView();
}
private void initView(){
vp_all_pictures = (ViewPager) findViewById(R.id.vp_all_pictures);
vp_all_pictures.setAdapter(new MyPagerAdapter(WatchPicturesActivity.this, picturesBean));
}
}
其中ViewPager的适配器为:
public class MyPagerAdapter extends PagerAdapter {
private Context context;
private AllPictureBean.ShowapiResBodyBean.PagebeanBean.ContentlistBean picturesBean;
public MyPagerAdapter(Context context, AllPictureBean.ShowapiResBodyBean.PagebeanBean.ContentlistBean picturesBean) {
this.context = context;
this.picturesBean = picturesBean;
}
@Override
public int getCount() {
return picturesBean.getList().size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override