根据可用图片的数量,我使用 imageview 或 Gallery。当只有一张图片可用时,它会使用 imageview,这就像一个魅力。我使用来自 u niversalloader的图像加载器。图片在我的屏幕顶部全宽。
当有多张图片时,我使用带有 pagerindicators 的画廊。在较小的屏幕上,这可以正常工作。但是在平板电脑上,图片不会填满全屏,这很奇怪,因为单个图像视图会,而图像加载器可以完美地完成它的工作。我认为这与我的画廊设置有关。
画廊代码:
// define pager identifier
pager = (LinearLayout)findViewById(R.id.pager);
pagerdot1 =(ImageView)pager.findViewById(R.id.pager_dot_1);
pagerdot2 =(ImageView)pager.findViewById(R.id.pager_dot_2);
pagerdot3 =(ImageView)pager.findViewById(R.id.pager_dot_3);
venueImage = (ImageView)findViewById(R.id.venueImage);
venueGallery = (CustomGallery)findViewById(R.id.GVvenueImage);
imageLoader=new LargerImageLoader(this.getApplicationContext());
if(venue.photos.size()>1){//multiple photos --> gallery
if(venue.photos.size()==2){
pagerdot3.setVisibility(View.GONE);
}
venueGallery.setVisibility(View.VISIBLE);
venueImage.setVisibility(View.GONE);
String[] fotos = new String[venue.photos.size()];
for(int i=0;i<venue.photos.size();i++){
if(venue.photos.get(i).large !=null){
fotos[i] = venue.photos.get(i).large;
System.out.println(venue.photos.get(i).large);
}
}
ImagePagerAdapter galleryad = new ImagePagerAdapter(fotos);
venueGallery.setAdapter(galleryad);
venueGallery.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
switch(position) {
case 0:
pagerdot1.setImageResource(R.drawable.pager_oranje);
pagerdot2.setImageResource(R.drawable.pager_wit);
pagerdot3.setImageResource(R.drawable.pager_wit);
break;
case 1:
pagerdot2.setImageResource(R.drawable.pager_oranje);
pagerdot1.setImageResource(R.drawable.pager_wit);
pagerdot3.setImageResource(R.drawable.pager_wit);
break;
case 2:
pagerdot3.setImageResource(R.drawable.pager_oranje);
pagerdot2.setImageResource(R.drawable.pager_wit);
pagerdot1.setImageResource(R.drawable.pager_wit);
break;
default:
pagerdot1.setImageResource(R.drawable.pager_oranje);
pagerdot2.setImageResource(R.drawable.pager_wit);
pagerdot3.setImageResource(R.drawable.pager_wit);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapter) {
}
});
}else if(venue.photos.size() ==1 ){ //1 foto
if(venue.photos.get(0).large != null){
venueGallery.setVisibility(View.GONE);
venueImage.setVisibility(View.VISIBLE);
imageLoader.DisplayImage(venue.photos.get(0).large, venueImage);
} else{
setStandardPic();
}
pager.setVisibility(View.GONE);
//
} else{
setStandardPic();
}
与:
private class ImagePagerAdapter extends BaseAdapter {
private String[] images;
private LayoutInflater inflater;
ImagePagerAdapter(String[] images) {
this.images = images;
inflater = getLayoutInflater();
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = null;
RelativeLayout borderImg;
if (convertView == null) {
imageView = new ImageView(getBaseContext());
imageView.setLayoutParams(new LayoutParams(width,height)); // size
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setPadding(0,0,0,0);
imageView = (ImageView) inflater.inflate(R.layout.item_gallery_image, parent, false);
borderImg = new RelativeLayout(getBaseContext());
borderImg.setPadding(0,0,0,0);
borderImg.setBackgroundColor(Color.TRANSPARENT); // no color
}else {
imageView = (ImageView) convertView;
borderImg = (RelativeLayout) convertView;
}
imageLoader.DisplayImage(images[position], imageView);
borderImg.addView(imageView);
return borderImg;
}
}
顶部屏幕的xml:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/venueImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:fadingEdge="none"
android:scaleType="centerCrop"
android:src="@drawable/header_food" />
<com.hera.ontdekdelft.lazyloader.CustomGallery
android:id="@+id/GVvenueImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:fadingEdge="none"
android:scaleType="centerCrop"
android:visibility="gone" />
<ImageView
android:id="@+id/venueCategoryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/venuecategory_sights" />
<include
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
layout="@layout/gallery_pager" />
</RelativeLayout>
我的自定义画廊只是一个普通画廊,重写了 onFling 方法以获得更好的投掷设置。
我应该改变什么以使我的画廊在平板电脑屏幕上也能正常工作?