Android 相机预览中的透明图像
我需要在相机预览中设置一个透明图像,并对其进行缩放 我有相机预览,在上面的布局中,我放置了一个带有图像的imageview。这张图片只是一个边框,中间是透明的,但我看不到相机预览,我只看到一个白色背景的图片 这是我的XML:Android 相机预览中的透明图像,android,android-layout,android-camera,Android,Android Layout,Android Camera,我需要在相机预览中设置一个透明图像,并对其进行缩放 我有相机预览,在上面的布局中,我放置了一个带有图像的imageview。这张图片只是一个边框,中间是透明的,但我看不到相机预览,我只看到一个白色背景的图片 这是我的XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_gravity="left|top" android:scaleType="fitXY"
android:src="@drawable/red"/>
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
</FrameLayout>
</LinearLayout>
如果图像是透明的,为什么要放置白色背景
谢谢您需要使用RelativeLayout设置
图像视图
相机预览
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:scaleType="fitXY"
android:src="@drawable/red"/>
</RelativeLayout >
问题与相机预览无关,只取决于您选择的视图组 线性布局将其子对象彼此并排排列,而不是按照您的意愿排列在顶部。在布局中,线性布局正在消耗片段或活动中的所有可见空间,因为其宽度和高度设置为
match\u parent
。同样,您的ImageView也在做同样的事情,并且占用了LinearLayout的所有可见空间。随后,FrameLayout不再适合并消失在屏幕外的某个位置
您可能希望改用FrameLayout(如果您希望对视图在其中的位置进行更细粒度的控制,可以使用RelativeLayout)。但是这样,ImageView就适合RelativeLayout,如果FrameLayout预览更小,我该怎么办?我需要一个相机预览(帧布局)的精确大小的图像视图。