我有一个带有 3 张幻灯片的 ViewPager。在每张幻灯片上,我希望能够添加 3 张图像和几个不同的文本标签。我目前拥有的代码允许我为每张幻灯片添加一个图像。我对如何使用每张幻灯片的多个图像和文本来完成这项工作感到困惑。任何帮助,将不胜感激。
public class ImageAdapter extends PagerAdapter {
private final Context context;
private final int[] GalImages = new int[] {
R.drawable.workout_widget_master,
R.drawable.workout_widget_master,
R.drawable.workout_widget_master
};
ImageAdapter(Context context){
this.context=context;
}
@Override
public int getCount() {
return GalImages.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = 10;
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.MATRIX);
imageView.setImageResource(GalImages[position]);
container.addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((ImageView) object);
}
}