开发者

Android How to display list image

Hi all

I'm developing my app. And I need your help:

I have a linearlayout, which is draw the image that I scanned using camera.

I can scan multiple time, to make multiple image files.

I want to add a child view to display all 开发者_运维技巧images that i scanned in the same view.

In that child view, i can slide to left, right to display continous image, like playing-image in music player.

Please suggestion: How to do like that?

Thank you very much!


I think using Gallery is better option.

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;
    }
  }
}

Add image to imageArray and call notifyDataSetChanged() method on adapter instance. Further information follow this link here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜