2011-11-07 15 views
1

Galleryウィジェットアダプタクラスを使用して画像を遅延読み込みします.Webサービスから取得した画像は640x431です。私は、画面の高さが何であっても同じアスペクト比を維持しながら、画像を幅で塗りつぶしたい。アダプタを使用してGalleryウィジェットの画像を適切に拡大する

このタイプのスケーリングをどのように処理するかはわかりません。

public class GalleryImageAdapter extends BaseAdapter{ 

    private Activity activity; 
    private ArrayList<String> listOfImages; 
    public ImageLoader imageLoader; 


    public GalleryImageAdapter(Activity a, ArrayList<String> listOfImages){ 
     activity = a; 
     this.listOfImages = listOfImages; 
     imageLoader=new ImageLoader(activity.getApplicationContext()); 
    } 

    @Override 
    public int getCount() { 
     return listOfImages.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return listOfImages.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup viewGroup) { 
     View v = convertView; 


     if (v == null) { 
      LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = vi.inflate(R.layout.gallery_layout, null); 

     } 


     final String url = listOfImages.get(position); 


     ImageView galleryImage = (ImageView) v.findViewById(R.id.galleryImage); 
     imageLoader.DisplayImage(url, activity, galleryImage); 
     return v; 
    } 

} 

gallery_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/galleryImage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="centerInside"/> 

</LinearLayout> 
+0

ちょうど関連ガイドの検索があった、それは私を助け、投票しました... –

答えて

1

私が正しく理解していれば、表示されているときに現在の画像がウィジェットの全幅になるようにしたいとします(横にスクロールするまで、次の画像と前の画像は表示されません)。あなたは次のようにあなたのアダプタのgetView()メソッドから返されたビューのLayoutParamsを設定する必要が

ImageViewScaleTypeについては

@Override 
public View getView(int position, View convertView, ViewGroup viewGroup) { 

    // current code here .. 

    v.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT, 
     LayoutParams.MATCH_PARENT)); 
    return v; 
} 

を、あなたは画像全体が空間に合うようにしたい場合はcenterInsideを使用し、それを切り抜くのが良ければcenterCropを使用してください。

+0

ありがとうございます。たとえ高解像度であっても、すべての画像がぼやけて見えます。 – Adam

0

あなたはfill_parentに高さと幅を設定し、setScaleTypeを使用することができます。

以下は、私のギャラリーアダプタです。おそらくScaleTypeCENTER_INSIDEを使用します。

+0

これは何もしません。画像のデフォルトの状態は、親指が小さくて中央にあり、画面の幅を埋めていないということです。親指も次のものと重なるように見える。 – Adam

+0

'gallery_layout'の内容を投稿できますか? – kabuko

関連する問題