Android 不调整大小/拉伸摄影机预览
这是我的相机支架:Android 不调整大小/拉伸摄影机预览,android,android-studio,android-camera,preview,Android,Android Studio,Android Camera,Preview,这是我的相机支架: <SurfaceView android:id="@+id/cameraPreview" android:layout_width="match_parent" android:layout_height="300dp" /> 我的问题是android会拉伸相机预览,即使我设置了PreviewSize也不行!! 请帮忙 SurfaceView与
<SurfaceView
android:id="@+id/cameraPreview"
android:layout_width="match_parent"
android:layout_height="300dp" />
我的问题是android会拉伸相机预览,即使我设置了PreviewSize也不行!!
请帮忙 SurfaceView与ImageView不同,它没有保持纵横比的内置过程。克服此缺陷的可用方案分为将SurfaceView嵌入具有受控宽度和高度的容器中,以及在onMeasure中设置SurfaceView的宽度和高度。[RESOLVED][IT WORKS][:D] 我已经解决了这样的问题:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/mySurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
// put widgets here
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/my_mask" /> //put a transparent image or a mask for your SurfaceView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
// put widgets here
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
附言:如果它也适合你,别忘了喜欢它 看看AspectFrameLayout在Grafika中的使用,例如在PlayMovieSurfaceActivity中。这不是一个通用的解决方案。它假定相机预览纵横比与屏幕纵横比匹配,而屏幕纵横比不适合许多设备,例如Nexus 4。