根据可用图片的数量,我使用图像视图或图库。当只有一张照片可用时,它会使用imageview,就像魅力一样。我使用了来自你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方法覆盖了更好的投影设置。
我应该更改什么才能让我的画廊在平板电脑屏幕上也能正常工作?
答案 0 :(得分:0)
目前尚不清楚你的宽度和高度来自哪里...... 我没有平板电脑,但这在我的星系笔记和模拟器上运行良好。您的高度数学可能会有所不同,具体取决于图像的纵横比。
screen_width和screen_height进入适配器的构造函数:
主要活动中的
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screen_width = size.x;
screen_height = size.y;
适配器getview
@Override
public View getView(int postion, View view, ViewGroup group)
{
ImageView imageView = new ImageView(_context);
imageView.setImageResource(imageIds[postion]);
imageView.setScaleType(ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(_screen_width, (int) ((double)_screen_height/2.5)));
return imageView;
}