2012-09-09 34 views
13

Estoy desarrollando una aplicación en la que el usuario tomará una fotografía de la cámara y la mostrará en la pantalla de vista previa con vista de imagen.Barra de progreso de Android en ImageView

**CameraCapture.java** 

class ButtonClickHandler implements View.OnClickListener 
{ 
    public void onClick(View view){ 
     myVib.vibrate(50); 
     startCameraActivity(); 
    } 
} 

protected void startCameraActivity() 
{ 
    File filenew = new File(_path); 
    Uri outputFileUri = Uri.fromFile(filenew); 

    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
    startActivityForResult(intent, 0); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    switch(resultCode) 
    { 
     case 0: 
      break; 

     case -1: 
      //pictaken++; 

      onPhotoTaken(); 

      break; 
    } 
} 

protected void onPhotoTaken() 
{ 
    //pictaken=true; 

    Intent i = new Intent(CameraCapture.this,Preview.class); 
    startActivity(i); 
} 

En mi clase de vista previa de la imagen capturada aparece en ImageView

**Preview.java** 

File imgFile = new File("/sdcard/DCIM/Camera/test.jpg"); 
if(imgFile.exists()){ 

    // Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 

    ImageView myImage = (ImageView) findViewById(R.id.image); 
    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
    Matrix mat = new Matrix(); 
    String degree="90"; 
    mat.postRotate(Integer.parseInt(degree)); 
    Bitmap bMapRotate = Bitmap.createBitmap(myBitmap, 0, 0,myBitmap.getWidth(),myBitmap.getHeight(), mat, true); 
    myImage.setImageBitmap(bMapRotate); 
    //myImage.setImageBitmap(myBitmap); 

} 
_image = (ImageView) findViewById(R.id.image); 

¿Hay alguna manera de mostrar barra de progreso en la ImageView hasta que se cargue la imagen capturada desde la tarjeta SD. Thnx de antemano :)

Respuesta

30

Coloque su ImageView y Progressbar en una RelativeLayout. Para su ProgressBar, utilice:

android:layout_centerInParent="true" 

los que se centrará en el RelativeLayout, es decir, sobre el ImageView. También puede ser que desee ocultar ProgressBar cuando la imagen se haya cargado:

progressBar.setVisibility(View.Gone) 

cuando la imagen se ha cargado.

Código de ejemplo:

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true"/> 

     <ProgressBar 
      style="?android:attr/progressBarStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:visibility="visible"/> 

    </RelativeLayout> 
+0

genial, pero cómo recibir una notificación cuando la imagen se haya cargado? –

3

Ésta es mi solución. Es un poco diferente. Puede usarlo para crear una vista de introducción con una imagen y una barra de progreso. Aquí, la barra de progreso está a 150dp en la parte inferior del centro. FrameLayout también se puede utilizar.

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:contentDescription="@string/intro_description" 
     android:scaleType="fitXY" 
     android:src="@drawable/intro" /> 

    <ProgressBar 
     android:id="@+id/progress" 
     style="?android:attr/progressBarStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="150dp" 
     android:visibility="visible" /> 

</FrameLayout>