Android如何显示列表图像

Android如何显示列表图像

问题描述:

大家好
我正在开发我的应用程序。我需要你的帮助:

我有一个linearlayout,这是绘制我使用相机扫描的图像。
我可以多次扫描,制作多个图像文件。
我想添加一个子视图来显示我在同一视图中扫描的所有图像。
在该子视图中,我可以滑动到左侧,右侧显示连续图像,如播放音乐播放器中的图像。

请指教:如何做到这一点?
非常感谢!Android如何显示列表图像

我认为使用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