4

无论如何要在 android 中将 ImageView 放在另一个前面。例如,我有一个大图像以及如何将一个小图像放在大图像的左上角。像小的东西会与大的重叠。谢谢你的帮助

4

6 回答 6

14

将图像包装在 RelativeLayout 中。将您想要的图像放在 xml 的最后,如下所示:

<RelativeLayout
    ...>
    <ImageView
        android:background="@drawable/backgroundimage"
        ... />
    <ImageView
        android:background="@drawable/foreground"
        ... />
</RelativeLayout>
于 2013-09-16T16:37:38.583 回答
5

使用 framelayout 作为根布局,然后放置大图像,然后放置小图像

像这样

<framelayout
......
......
......>

<ImageView 
// your big image
......
.....
.....>
</ImageView>



<ImageView 
// your Small image
......
.....
.....>
</ImageView>


</framelayout>
于 2013-09-16T16:39:53.057 回答
3

对我来说 frameLayout 是最好的选择,而不是你只需要调用这条线

ImageViewSmall.bringToFront();

甚至不需要这一行,只需从代码 imageViews 先大后小创建。位置 xy 也与:

ImageViewSmall.setX( float X );
ImageViewSmall.setY( float X );
于 2016-11-16T12:56:58.303 回答
0

您可以使用相对布局;你可以测试这段代码,我测试了它,它工作正常:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/a_t1"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_marginLeft="10dp"
    android:background="#000000" />

<ImageView
    android:id="@+id/a_t2"
    android:layout_width="34dp"
    android:layout_height="34dp"
    android:layout_gravity="top|left"
    android:background="#c12fff" />

于 2013-09-16T16:59:23.660 回答
0

按照 Randy 的建议,我用它在缩略图上创建了一个视频“播放”叠加层。

这是一些稍微更完整的代码,它还确保图像在父对象中居中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center">

    <ImageView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/ivBackground"
            android:scaleType="fitCenter"
            android:layout_centerInParent="true"
            android:src="@drawable/downloadplaceholder"/>

    <ImageView
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:scaleType="fitCenter"
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"
            android:id="@+id/ivPlayOverlay"
            android:src="@drawable/play_button_overlay"/>
</RelativeLayout>
于 2013-09-16T16:40:16.600 回答
0

我曾尝试在线性布局前使用编辑文本做类似的事情,我发现仅将编辑文本的 XML 放在线性布局的 XML 之后,就会在应用程序运行时将其置于顶部。希望这可以帮助。

于 2018-04-06T12:32:51.200 回答