2011-05-13 40 views
1

我正在使用圖庫來顯示一些圖像。我已經使用下面的adpater和gallery選擇器來進行圖庫項目選擇。圖庫選擇的項目背景不存在

ImageAdapter:

public class AddImgAdp extends BaseAdapter { 

     private int[] galleryImages; 

     public AddImgAdp(int[] images) { 
      galleryImages = images; 


     } 

     public int getCount() { 
      return galleryImages.length; 
     } 

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

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

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

      final ImageView iv = new ImageView(ChooseLinerActivity.this); 
      iv.setImageResource(galleryImages[position]); 
      iv.setScaleType(ImageView.ScaleType.FIT_XY); 
      iv.setLayoutParams(new Gallery.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
      iv.setBackgroundDrawable(getResources().getDrawable(
        R.drawable.galleryselector)); 


       iv.setAdjustViewBounds(true); 

      return iv; 

     } 
    } 

galleryselector:

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item android:state_selected="true" 
         android:drawable="@drawable/large_button_sel2"/> 
     <item android:drawable="@android:color/transparent" /> 
</selector> 

我的問題是,當我點擊或通過畫廊滾動它顯示的背景,但是當我點擊另一種觀點認爲這是在畫廊視圖,則該選擇消失。

+0

你有沒有得到你的問題的答案。 – Prateek 2013-01-24 10:34:09

回答

0

因爲當您點擊圖庫下的另一個視圖時,您的圖庫未聚焦。因爲您的圖庫中的視圖未被選中。

+1

請爲平凡的答案寫評論。 – 2012-10-28 16:32:54

相關問題