将一张图片放在另一张在 Android 中拉伸的图片上
我有一个用户界面,其中我曾经将图像作为背景,因此它会自行拉伸以填充屏幕。我想将另一张图像放置在原始图像的特定位置。我该怎么做?
为了详细说明,假设我有一个 320x320 的图像,它位于背景,并且在 (50,50)(左上角) 处有一个 20x20 的白色正方形。我有另一张 20x20 的图像应该填充它。现在当背景拉伸时,我希望该图像拉伸并填充它。相应地放置以适合该白色盒子本身。
例如,假设我跟踪了带有 2 个黄色框的 bckgrnd 图像。现在前景图像将准确放置在上方的黄色框中。由于背景图像会扩展/收缩(沿 x 和 y 方向的差异太大),因此前景也应拉伸并定位自身以适合黄色框。
背景图片:http://oi52.tinypic.com/2yn5nut.jpg
前景图片:http://i52.tinypic.com/dm3503.png
这是我现在的 xml 文件。 Pt.(32,47) 是背景图像中顶部黄色框的左上角
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/bkgrnd">
<ImageView android:id="@+id/imageView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/foregrnd"
android:scaleType="fitXY" android:layout_marginTop="42px"
android:layout_marginLeft="37px">
</ImageView>
</RelativeLayout>
I have a UI in which I have once image as background and Hence it stretches itself to fill the screen. I want to place another image at a particular position w.r.t. original image. How do I do that?
To elaborate more,say I have an image of 320x320 which is at background, and has a white square of 20x20 in it at (50,50)(left top corner) . I have another image of 20x20 which should fill it in. Now when the background stretches, I want this image to stretch & place accordingly so as to fit in that white box itself.
e.g. lets say I've following bckgrnd images with 2 yellow boxes. Now the foregroud image is to be placed exactly in upper yellow box. Since the background image expands/shrinks (that too differently along x and y), the foreground should also stretch and position itself to fit the yellow box.
Background Image: http://oi52.tinypic.com/2yn5nut.jpg
Foreground Image: http://i52.tinypic.com/dm3503.png
This is my xml file as of now. Pt.(32,47) is the top left corner of top yellow box in background img
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/bkgrnd">
<ImageView android:id="@+id/imageView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/foregrnd"
android:scaleType="fitXY" android:layout_marginTop="42px"
android:layout_marginLeft="37px">
</ImageView>
</RelativeLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请告诉我你使用什么布局???
根据我的理解,我认为你有 2 张图像,你想要一张作为背景图像,另一张图像作为前景图像。
为此,您可以使用相对布局并将其高度和宽度设置为“fill_parant”
并将您的第一张图像设置为相对布局的背景。使用 android:background = "firstimage"
,然后将另一个图像视图放置在您想要的位置。
please tell me about what layout are you using???
according to my understanding i think u have 2 images and u want one as background image and other image as your foreground image.
For this you can use the relative layout and set its height and width as "fill_parant"
and set your first image as the background of relative layout. using android:background = "firstimage"
and then place the other image view where ever you want.