在ImageView中显示全屏图像

时间:2014-01-31 11:11:21

标签: android imageview parse-platform

我想在点击图片浏览后在其他活动上显示全屏图像。我的布局中有6个ImageView,每个ImageView都从Parse后端获取图像。如何在获取图像路径时显示图像?

public ImageLoader imgl;
ImageView ad1,ad2,ad3,ad4,ad5,ad6;   
 List<ParseObject> ob;
 private ImageView[] imgs = new ImageView[5];
 int k=0;

ad1=(ImageView) findViewById(R.id.ad1);
            ad2=(ImageView) findViewById(R.id.ad2);
            ad3=(ImageView) findViewById(R.id.ad3);
            ad4=(ImageView) findViewById(R.id.ad4);
            ad5=(ImageView) findViewById(R.id.ad5);
            ad6=(ImageView) findViewById(R.id.ad6);
             imgs[0] = ad2; 
             imgs[1] = ad3; 
             imgs[2] = ad4; 
             imgs[3] = ad5; 
             imgs[4] = ad6;

                 ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Adverts");
                 query.orderByDescending("updatedAt");
                 query.whereEqualTo("Status", true);

                 try {
                    ob = query.find();
                     System.out.println("the urls areeee "+ob);
                     for (ParseObject country : ob) {
                         ParseFile image = (ParseFile) country.get("imageFile");
                         imgl.DisplayImage(image.getUrl(), imgs[k]);
                         k=k+1;
                         System.out.println("the urls are"+image.getUrl());
                         pd.dismiss();
                            }
                } catch (com.parse.ParseException e) {
                    // TODO Auto-generated catch block
                    pd.dismiss();
                    e.printStackTrace();
                }

                    ad1.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View view) {
                            Intent ent= new Intent(HomeActivity.this,AdvertsActivity.class);

                            startActivity(ent); 
                    }
                });

            }

1 个答案:

答案 0 :(得分:0)

在ImageView上设置单击侦听器,并在参数和调用方法

中传递图像URL
    private void viewImage(String url)
    {
        final Dialog nagDialog = new Dialog(ProjectDetailActivity.this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        nagDialog.setCancelable(false);
        nagDialog.setContentView(R.layout.dialog_full_image);
        ivPreview = (ImageView)nagDialog.findViewById(R.id.imageView1);
        BitmapDrawable bmd = (BitmapDrawable)getDrawableFromUrl(url)
        Bitmap bitmap = bmd.getBitmap();
        ivPreview.setImageBitmap(bitmap);
        nagDialog.show();
    }

    public Drawable getDrawableFromUrl(String imgUrl) 
    {
        if(imgUrl == null || imgUrl.equals(""))
            return null;
        try 
        {
            URL url = new URL(imgUrl);
            InputStream in = url.openStream();
            Drawable d = Drawable.createFromStream(in, imgUrl);
            return d;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

使用xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:layout_gravity="center" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/hello_world"
        android:src="@android:color/white" 
        android:layout_margin="5dp"
        android:scaleType="centerInside"/>
</RelativeLayout>