2012-05-29 71 views

回答

0

我想你可以使用網格視圖並將其與View分頁器結合使用。這是你如何做到這一點的一個例子。

public class GridGallery extends BaseAdapter { 

    Context context; 

    public GridGallery(Context context) { 
     this.context = context; 
    } 

    @Override 
    public int getCount() { 
     return numberOfImages; 
    } 

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

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

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


     final ImageView view; 

     if(convertView == null) { 

      view = new ImageView(context); 

      view.setScaleType(ImageView.ScaleType.FIT_CENTER); 
      view.setLayoutParams(new GridView.LayoutParams(screenWidth/4, screenHeight/4)); 
      view.setAdjustViewBounds(false); 
      view.setPadding(2, 2, 2, 2); 

      view.setOnLongClickListener(new View.OnLongClickListener() { 

       @Override 
       public boolean onLongClick(View v) { 
        // You can set your View Pager adapter here 
        // 
        return false; 
       } 
      }); 

     if(view!=null) { 
      // Here you can download your images from internet. 
      thumbnailLoader.DisplayImage(urlList.get(position), view); 
      notifyDataSetChanged(); //Calling this helped to solve the problem. 

      view.setTag(position); 
     } 

     return view; 
    }  
} 
+1

這不是一個完整的解決方案,但它可以給你一個想法。如果您想從圖庫(完全是android圖庫)獲取圖像,您可以按照我的說法使用視圖分頁器,並且可以從sd卡或Android內部存儲圖像的內部存儲器中獲取圖像。 – osayilgan

相關問題