2014-01-31 121 views
1

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

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

      } 

回答

0

集点击收听,并通过您的图片网址参数,调用方法

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> 
+0

谢谢,但如何从URL中的位图和设置图像视图? – addy123

+0

chk编辑答案 –

+0

Thanx为答案,它适用于特定的imageView和特定的图像。但是,因为我正在动态地设置ImageViews数组中的图像,所以我如何将它设置为imgs [5]。所以当我点击一个特定的ImageView时,我只能得到那个图像。 – addy123