创建图片廊使用可绘制图像资源文件夹 [英] Creating Image Gallery using Drawable images in res folder

查看:96
本文介绍了创建图片廊使用可绘制图像资源文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我没有要求了。我需要在res /可绘制文件夹,然后运行该应用程序我应该在选择任何图像,我应该显示此图像中的新的活动显示在listView.and这个图像增加约10张图像应能放大和缩小。请帮我找出这个与样品code。

I am new to android. I have a requirement now. I need to add around 10 images in the res/drawable folder and on running the app i should display this images on a listView.and on selecting any of the image i should display this image in the new activity should be able to zoom in and zoom out. Please help me out to figure out this with the sample code.

在此先感谢。

推荐答案

本例中为创建画廊,选择一个并设置为selectedImageView。     所以以后你可以做一切与selectedImageView。

this example for create Gallery, select one and set to selectedImageView. so after that you can do everything with selectedImageView.

  public class MyActivity extends Activity{

    private int selectedImagePosition = 0;
    private ImageView selectedImageView;
    private List<Drawable> drawables;
    private Gallery gallery;    


    @Override
    public void onCreate(Bundle savedInstanceState) {
      selectedImageView = (ImageView) view.findViewById(R.id.selected_imageview);
      getDrawablesList();

      gallery = (Gallery) view.findViewById(R.id.Gallery);
      gallery.setAdapter(new ImageAdapter(getActivity().getApplicationContext()));

      gallery.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v, final int position, long id) {

        setSelectedImage(selectedImagePosition);

    }
    });



     private void getDrawablesList() {
            drawables = new ArrayList<Drawable>();
            drawables.add(getResources().getDrawable(R.drawable.res1));
            drawables.add(getResources().getDrawable(R.drawable.res2));
            drawables.add(getResources().getDrawable(R.drawable.res3));
            drawables.add(getResources().getDrawable(R.drawable.res4));
        }

    private void setSelectedImage(int selectedImagePosition) {

            BitmapDrawable bd = (BitmapDrawable) drawables.get(selectedImagePosition);
            Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.9), (int) (bd.getIntrinsicWidth() * 0.7), false);
            selectedImageView.setImageBitmap(b);
            selectedImageView.setScaleType(ScaleType.FIT_XY);

        }

这篇关于创建图片廊使用可绘制图像资源文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆