我是android新手。我在图像视图底部有一个带摄像头按钮的图像视图。无论何时单击按钮,摄像机都应打开并捕获图像。此捕获的图像应保存在内存中,imageview现在必须显示此捕获的图像。单击摄像机按钮时,必须保存新图像,并且imageview必须显示此图像。
如何设置这种类型的布局,并将相机按钮放置在图像视图的底部?
答案 0 :(得分:2)
Well You can use this layout..
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:ignore="MissingPrefix">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/bicycle" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_5dp"
android:clickable="true"
app:fabSize="mini"
android:src="@android:drawable/ic_menu_camera"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Hope it'll help
答案 1 :(得分:0)
您可以使用Intent从图库或相机中选择图像
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, KEY);
\\KEY is final String with any value
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 7 && resultCode == RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}
检查以下示例 http://www.android-examples.com/capture-image-from-camera-and-display-in-imageview-android/