我正在开发一个应用程序,用户将在相机中拍摄照片并将其显示在具有图像视图的预览屏幕上。
**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 );
是否有任何方法可以在ImageView上显示进度条,直到它从SD卡加载捕获的图像。 Thnx提前:))
答案 0 :(得分:33)
将ImageView和Progressbar放在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>
答案 1 :(得分:5)
这是我的解决方案。它有点不同。您可以使用它来创建带有图像和进度条的介绍视图。进度条位于中心底部150dp处。 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>