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」' –