将ImageView带到另一个面前?

时间:2013-09-16 16:32:16

标签: android imageview

无论如何,在Android中将ImageView带到另一个前面。例如,我有一个大图像,我如何在大的左上角放一个小图像。像小的一个将重叠大的一个。谢谢你的帮助

6 个答案:

答案 0 :(得分:11)

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

<RelativeLayout
    ...>
    <ImageView
        android:background="@drawable/backgroundimage"
        ... />
    <ImageView
        android:background="@drawable/foreground"
        ... />
</RelativeLayout>

答案 1 :(得分:4)

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

像这样

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

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



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


</framelayout>

答案 2 :(得分:1)

对我来说frameLayout最好选择, 比你只需要拨打这一行

ImageViewSmall.bringToFront();

甚至不需要这条线,只需从代码imageViews创建第一个大的小。位置x y也与:

ImageViewSmall.setX( float X );
ImageViewSmall.setY( float X );

答案 3 :(得分: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>

答案 4 :(得分:0)

你可以使用RelativeLayout;你可以测试这段代码,我测试它并且工作正常:

<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" />

答案 5 :(得分:0)

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

相关问题