在我向右或向左滑动2次之前,ViewPager图像不会显示 我使用app appcompat 7v最新版本
我的图片显示当我滑动两次滑动时,当回到位置时,我的图像已加载。
public class FullScreenViewActivity extends Activity
{``
Context context;
DataSource datasource;
ViewPager pager;
@Override
protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen_view);
context = this;
datasource = new DataSource(this);
final PageIndicator indicator = (PageIndicator) findViewById(R.id.indicator);
pager = (ViewPager) findViewById(R.id.pager);
pager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int index) {}
@Override
public void onPageScrolled(int startIndex, float percent, int pixel) {
indicator.setPercent(percent);
// Log.i("LOG", "Percent: " + startIndex + ", " + percent);
indicator.setCurrentPage(startIndex);
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
Resources r = getResources();
float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, AppConstant.GRID_PADDING, r.getDisplayMetrics());
int columnWidth = (int) ((getScreenWidth() - ((AppConstant.NUM_OF_COLUMNS + 1) * padding)) / AppConstant.NUM_OF_COLUMNS);
String url = getIntent().getExtras().getString("url");
String position = getIntent().getExtras().getString("position");
String id = getIntent().getExtras().getString("id");
// Toast.makeText(context, position, Toast.LENGTH_LONG).show();
int pos = Integer.parseInt(position);
// ArrayList<StructureImage2> images = datasource.getGalleryImage2(id);
ArrayList<String> img = datasource.getGalleryImage3(id);
ArrayList<Integer> img4 = datasource.getGalleryImage4(id);
GalleryImageAdapter adapter = new GalleryImageAdapter(FullScreenViewActivity.this, this, img, img4, 100);
pager.setAdapter(adapter);
pager.setCurrentItem(pos);
// ImageLoader imageloader = new ImageLoader(context);
// View view = G.inflater.inflate(R.layout.sample, null);
// ImageView imageofsample = (ImageView) view.findViewById(R.id.imageofsample);
// imageloader.DisplayImage(G.context.getString(R.string.gallery_image_link) + img.get(pos), imageofsample, 200);
}
在我的图片中,它是我的代码 我的galleryimageadaptercode
public class GalleryImageAdapter extends PagerAdapter {
Context context;
ArrayList<String> array;
ArrayList<Integer> intarray;
Activity activity;
ImageLoader imageloader;
int columnWidth;
public GalleryImageAdapter(Activity activity, Context context, ArrayList<String> array, ArrayList<Integer> intarray, int columnWidthe) {
this.context = context;
this.array = array;
this.intarray = intarray;
this.activity = activity;
imageloader = new ImageLoader(context);
this.columnWidth = columnWidth;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return array.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = G.inflater.inflate(R.layout.sample, null);
ImageView imageofsample = (ImageView) view.findViewById(R.id.imageofsample);
TextView textofsample = (TextView) view.findViewById(R.id.textofsample);
imageloader.DisplayImage(G.context.getString(R.string.gallery_image_link) + array.get(position), imageofsample, 200);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
} // GalleryImageAdapter的结尾
答案 0 :(得分:1)
public class GalleryImageAdapter extends PagerAdapter {
Context context;
ArrayList<String> array;
ArrayList<Integer> intarray;
Activity activity;
ImageLoader imageloader;
int columnWidth;
List<View> viewlist = new ArrayList();
public GalleryImageAdapter(Activity activity, Context context, ArrayList<String> array, ArrayList<Integer> intarray, int columnWidthe) {
this.context = context;
this.array = array;
this.intarray = intarray;
this.activity = activity;
imageloader = new ImageLoader(context);
this.columnWidth = columnWidth;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return array.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = G.inflater.inflate(R.layout.sample, null);
ImageView imageofsample = (ImageView) view.findViewById(R.id.imageofsample);
TextView textofsample = (TextView) view.findViewById(R.id.textofsample);
imageloader.DisplayImage(G.context.getString(R.string.gallery_image_link) + array.get(position), imageofsample, 200);
container.addView(view,position);
viewlist.add(position,view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// container.removeView((View) object);
container.removeView(viewlist.get(position));
}
}