请帮我。我正在关注 Chris Banes ( https://github.com/chrisbanes/PhotoView ) 的示例 PhotoView 中的示例 ViewPagerActivity ,我想使用 Picasso URL 图像更改可绘制对象。所以,我试图通过 Picasso String 的 url 数组将多个图像放入 HackyViewPager。
我的 xml ViewPager:
<my.package.HackyViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="200dp" />
在 onCreate 中:
...
ViewPager viewPager = (HackyViewPager) findViewById(R.id.view_pager);
viewPager.setAdapter(new SamplePagerAdapter());
我有一个从单个 String stringDefinitionGemstonesPhoto 获得的 URL 字符串数组
String[] strAry = stringDefinitionGemstonesPhoto.split(",");
SamplePageAdapter 中的最终代码是:
static class SamplePagerAdapter extends PagerAdapter {
private String stringDefinitionGemstonesPhoto = ("https://geology.com/minerals/photos/calcite-marble-127.jpg, https://geology.com/minerals/photos/calcite-concrete.jpg");
private String[] strAry = stringDefinitionGemstonesPhoto.split(",");
@Override
public int getCount() {
return strAry.length;
}
@Override
public View instantiateItem(ViewGroup container, int position) {
PhotoView photoView = new PhotoView(container.getContext());
System.out.println(strAry[position]);
Picasso.get().load(strAry[position]).into(photoView);
container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return photoView;
}
@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;
}
}
仅显示一张图像,当我滑动时,下一张照片为空/空白。在日志系统中打印出正确拆分的链接。怎么了?