2011-04-04 75 views
0

大家好
我正在開發我的應用程序。我需要你的幫助:

我有一個linearlayout,這是繪製我使用相機掃描的圖像。
我可以多次掃描,製作多個圖像文件。
我想添加一個子視圖來顯示我在同一視圖中掃描的所有圖像。
在該子視圖中,我可以滑動到左側,右側顯示連續圖像,如播放音樂播放器中的圖像。

請指教:如何做到這一點?
非常感謝!Android如何顯示列表圖像

回答

0

我認爲使用Gallery是更好的選擇。

public class GalleryExample extends Activity { 

    private Gallery gallery; 
    private ImageView imgView; 

    private Integer[] Imgid = { 
    R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, 
    R.drawable.a_6, R.drawable.a_7 
    }; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    imgView = (ImageView)findViewById(R.id.ImageView01); 
    imgView.setImageResource(Imgid[0]); 

    gallery = (Gallery) findViewById(R.id.examplegallery); 
    gallery.setAdapter(new AddImgAdp(this)); 

    gallery.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView parent, View v, int position, long id) { 
     imgView.setImageResource(Imgid[position]); 
     } 
    }); 

    } 

    public class AddImgAdp extends BaseAdapter { 
    int GalItemBg; 
    private Context cont; 

    public AddImgAdp(Context c) { 
     cont = c; 
     TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme); 
     GalItemBg = 
      typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); 
     typArray.recycle(); 
    } 

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

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

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

    public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView imgView = new ImageView(cont); 

     imgView.setImageResource(Imgid[position]); 
     imgView.setLayoutParams(new Gallery.LayoutParams(80, 70)); 
     imgView.setScaleType(ImageView.ScaleType.FIT_XY); 
     imgView.setBackgroundResource(GalItemBg); 

     return imgView; 
    } 
    } 
} 

添加圖片到imageArray並呼籲適配器實例notifyDataSetChanged()方法。更多信息請點擊此鏈接here

+0

謝謝!我會盡量按照你的說法和以後的反饋。 – Eimatsu 2011-04-04 11:38:39