0
我有一个布局,其中包含两个带有一些叠加层的大图像。围绕缩放环绕ViewGroup“紧密”ImageView
在图像的顶部,有一个半透明的背景。这是问题出在哪里:
图像位于布局的水平中心,有android:scaleType="fitCenter"
。这是如何正确显示图像。然而,半透明背景占据了布局的整个宽度,而不是将其自身限制为imageview。我想是半透明的酒吧只占据图像的宽度。
我怎么能得到半透明的部分只占用图像,最好只与XML?
当前XML布局(导致图像以上):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="#222">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="4dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/test_img_1"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"/>
<View android:id="@+id/blur_user"
android:layout_width="match_parent"
android:layout_height="36dp"
android:alpha="0.7"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="36dp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:text="Some text"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/user_choice"
android:background="?attr/selectableItemBackground"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="4dp"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/test_img_1"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"/>
<View android:id="@+id/blur_installer"
android:layout_width="match_parent"
android:layout_height="36dp"
android:alpha="0.7"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="36dp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Some text"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/installer_choice"
android:background="?attr/selectableItemBackground"/>
</RelativeLayout>
</LinearLayout>
'机器人:scaleType = “fitXY”' –
@IntelliJAmiya:设置scaleType为'fitXY'不有所作为,据我所看到的。你能详细说明一下吗? – Marcel50506
在'RelativeLayout'和'ImageView'部分设置'android:layout_width ='match_parent''为测试用例注释'android:adjustViewBounds =“true”' –