私の Android アプリには、 http ://developer.android.com/guide/topics/media/camera.html#custom-camera のドキュメントを使用して SurfaceView として実装されたカメラ プレビューを表示するアクティビティがあります。
最初からこの SurfaceView の上に ImageView を表示したいのですが、ユーザーが最初の写真を撮ったときにそのレイアウト (幅、高さ、ソース イメージ) も更新したいと考えています。私の問題は、コードが最初のステップで機能することです。アクティビティの開始時に画像が SurfaceView に表示されますが、必要なときにレイアウトが変更されません。
XML は次のとおりです。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_capture"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CaptureActivity" >
<RelativeLayout
android:id="@+id/camera_preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<!-- Here I will programmatically add the SurfaceView -->
<ImageView
android:id="@+id/image_picture"
android:layout_width="100dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
android:contentDescription="picture preview"
android:src="@drawable/image1" />
</RelativeLayout>
<Button
android:id="@+id/button_capture"
android:text="Capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
/>
</FrameLayout>
SurfaceView は、次のスニペットで追加されます。
mPreview = new CameraPreview(this, mCamera);
RelativeLayout preview = (RelativeLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview, 0); //
これは、ImageView を更新する必要があるコードです (onPictureTaken()
メソッド内にあります)...しかし、機能しません:
LayoutInflater linf = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout frame = (FrameLayout) linf.inflate(R.layout.activity_capture, null);
ImageView imgw = (ImageView) frame.findViewById(R.id.image_left_picture); // get the ImageView
imgw.setImageResource(R.drawable.image2); // change its source image
imgw.setLayoutParams(new RelativeLayout.LayoutParams(w, h)); //change its size
invalidate(); // also tried to add this method call... nothing changes.