2017-01-09 5 views
0

onActivityResult 메서드 내에서 이미지 뷰를 동적으로 만들고 싶습니다.안드로이드에서 onActivityResult 메서드 내에서 이미지 뷰를 만드는 방법은 무엇입니까?

난 내이 같은 ImageView 정의하면이 코드를 완벽하게 imageView = (ImageView) findViewById(R.id.image_view); 작품 :

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == PICK_PHOTO && resultCode == RESULT_OK) { 
     Uri uri = data.getData(); 

     StorageReference photoStorageReference = storageReference.child(uri.getLastPathSegment()); 
     photoStorageReference.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { 
      @Override 
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
       Uri downloadUri = taskSnapshot.getDownloadUrl(); 
       Picasso.with(StorageActivity.this).load(downloadUri).fit().centerCrop().into(imageView); 
      } 
     }); 
    } 
} 

그러나 나는이 같은 onActivityResult 방법 내부에 이미지 뷰를 생성하는 경우 :

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if (requestCode == PICK_PHOTO && resultCode == RESULT_OK) { 
     Uri uri = data.getData(); 

     StorageReference photoStorageReference = storageReference.child(uri.getLastPathSegment()); 
     photoStorageReference.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { 
      @Override 
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
       Uri downloadUri = taskSnapshot.getDownloadUrl(); 
       ImageView imageView = new ImageView(getApplicationContext()); 
       linearLayout.addView(imageView); 
       Picasso.with(StorageActivity.this).load(downloadUri).fit().centerCrop().into(imageView); 
      } 
     }); 
    } 
} 

이미지보기 표시되지 않습니다. 나는 프로그래밍 방식으로 해당 이미지 뷰를 onCreate 메서드로 만들려고했지만 같은 문제가 발생했습니다. 아무 것도 표시되지 않습니다. 내가 대신 ImageView 버튼을 만들면 버튼이 올바르게 표시됩니다. 내 코드에 어떤 문제가 있습니까?

미리 감사드립니다.

답변

0

새로 추가 된보기의 LayoutParameters를 지정하지 않았습니다. 아래처럼

imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
+0

'LayoutParams'를 추가했지만 아무 것도 표시되지 않습니다. –

+0

실제 이미지로 ImageView를 설정 했습니까? – WenChao

+0

예,'imageView.setBackgroundResource (R.drawable.image);를 설정했으며 아무것도 표시되지 않았습니다. –