0

根据可用图片的数量,我使用 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 方法以获得更好的投掷设置。

我应该改变什么以使我的画廊在平板电脑屏幕上也能正常工作?

4

1 回答 1

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;
        }
于 2013-04-08T00:35:47.317 回答