gpt4 book ai didi

android - 如何叠加指定位置的 2 个 ImageView

转载 作者:行者123 更新时间:2023-11-29 16:08:21 28 4
gpt4 key购买 nike

我想放置 2 个 ImageView,一个放在另一个上面。这是一个正方形和圆形的示例。

enter image description here

我该怎么做?我只知道在运行时使用什么图像,所以我不能在 xml 文件中指定它们。

提前谢谢你。

最佳答案

您可以使用 FrameLayout相互堆叠 View 。

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_green" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_red"/>
</FrameLayout>

然后您可以设置 android:layout_margin="" 以正确定位 ImageView

请注意,FrameLayout 的最后一个 subview 是最可见的 View

关于android - 如何叠加指定位置的 2 个 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15889470/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com