2014-01-31 151 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