我正在创建一个应用程序,希望将摄像头预览限制在摄像头屏幕的80%左右。我可以使用layout_weight = 0.8完成它。现在,我需要在相机预览的一角实现边框。
我已附上我真正想完成的工作的快照。我真正想要的是红色显示的边框。任何指针都会有所帮助。
这是我将相机图像缩小到80%的方法。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent" android:gravity="center"
android:weightSum="1.0">
<LinearLayout android:orientation="vertical" android:id="@+id/surfaceparent"
android:layout_width="0dp" android:layout_height="match_parent"
android:layout_weight="0.8" android:gravity="center"
android:weightSum="1.0">
<SurfaceView android:id="@+id/camera_preview"
android:layout_width="fill_parent" android:layout_height="0dp"
android:layout_weight="0.8">
</SurfaceView>
</LinearLayout>
</LinearLayout>
最佳答案
将Surfaceview放置在相对布局中并在其上添加图像:
<RelativeLayout android:orientation="vertical" android:id="@+id/surfaceparent"
android:layout_width="0dp" android:layout_height="match_parent"
android:layout_weight="0.8" android:gravity="center"
android:weightSum="1.0">
<SurfaceView android:id="@+id/camera_preview"
android:layout_width="fill_parent" android:layout_height="0dp"
android:layout_weight="0.8">
</SurfaceView>
<ImageView android:src="@drawable/tl" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" />
<ImageView android:src="@drawable/tr" android:layout_alignParentTop="true" android:layout_alignParentRight="true" />
<ImageView android:src="@drawable/bl" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" />
<ImageView android:src="@drawable/br" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" />
</RelativeLayout>
或者,您可能会有一个9补丁映像
关于android - Android Camera Preview显示角落图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8368788/