Android 安卓:如何将一个透明图像放置在另一个具有精确宽度和高度的图像上
我有两张主图片和一张透明图片。船是从主_背景裁剪出来的,我想把裁剪好的图像船放在主_背景上,放在主_背景上船出现的确切位置上。当我使用 android:layout\u width=“match\u parent” android:layout\u height=“match\u parent” 这条船看起来像一条细长的船。当我使用“包装内容”而不是“匹配父项”时, 它显示为一个小图像。如何在主屏幕上设置船的确切宽度和高度 这是我的xml代码Android 安卓:如何将一个透明图像放置在另一个具有精确宽度和高度的图像上,android,Android,我有两张主图片和一张透明图片。船是从主_背景裁剪出来的,我想把裁剪好的图像船放在主_背景上,放在主_背景上船出现的确切位置上。当我使用 android:layout\u width=“match\u parent” android:layout\u height=“match\u parent” 这条船看起来像一条细长的船。当我使用“包装内容”而不是“匹配父项”时, 它显示为一个小图像。如何在主屏幕上设置船的确切宽度和高度 这是我的xml代码 <RelativeLayout xmlns:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main_bg"
android:gravity="left"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ship"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ship"
android:orientation="vertical">
</LinearLayout>
如何正确放置它?您应该尝试使用框架布局将一个图像叠加到另一个图像上。比如:
FrameLayout
Image
FrameLayout
Image
并根据需要设置框架布局的尺寸。您可以使用两个
FrameLayout
并执行以下操作:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/main_bg" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ship" >
</FrameLayout>
</FrameLayout>
使用本帖中的LayerImageView,查看带有如何放置层标志的示例您可以为版面设置src
和background
属性(即版面的前景和背景)。