17

ユーザーがカメラから写真を撮り、画像ビューを持つプレビュー画面に表示するアプリを開発しています。

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

私の Preview クラスでは、キャプチャされた画像が 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 );

SDカードからキャプチャされた画像をロードするまで、ImageViewにプログレスバーを表示する方法はありますか? 事前にt​​hnx :)

4

2 に答える 2

39

ImageViewとプログレスバーをRelativeLayoutに配置します。ProgressBarには、次を使用します。

android:layout_centerInParent="true"

これにより、RelativeLayoutの中央に配置されます。つまり、ImageView上に配置されます。画像が読み込まれたときにProgressBarを非表示にすることもできます。

progressBar.setVisibility(View.Gone)

画像が読み込まれたとき。

サンプルコード:

 <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>
于 2012-09-09T19:19:43.197 に答える
5

これが私の解決策です。少し違います。これを使用して、画像と進行状況バーを含むイントロ ビューを作成できます。ここでは、進行状況バーが中央の下部に 150 dp あります。FrameLayoutも使用できます。

<?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>
于 2013-12-17T17:39:22.480 に答える