在安卓系统中如何将一张图片覆盖在另一张图片上。

5

我有一个照片集,其中显示的图像带有白色边框和圆角。图像将会动态添加。我尝试使用帧布局,但对我来说它不起作用。我的尝试:在已经存在的圆形图像上添加动态图像。

<FrameLayout
   android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<ImageView 
    android:id="@+id/image"
    android:layout_width="60dip"
    android:layout_height="60dip"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop" />

<ImageView 
    android:id="@+id/imagef"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:background="@drawable/ph_bg" />
</FrameLayout>

上述的XML代码没有给出准确的结果...有什么想法吗?

你能发布一下应该得到的结果吗? - Pankaj Kumar
我想要我的动态生成的图像作为背景,静态图像作为前景。 - user2291423
2个回答

10

请使用以下 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="60dip"
        android:layout_height="60dip"
        android:adjustViewBounds="true"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop" />

    <ImageView
        android:id="@+id/imagef"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:background="@drawable/ph_bg" />

</RelativeLayout>

这将完成你的任务。

愉快编码 :)


1
尝试在一个ImageView上设置前景和背景。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/your_img_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/the_actual_image"
        android:src="@drawable/the_image_overlay" />

</RelativeLayout>

我们如何在ImageView上设置前景色? - Ajay
使用android:src...来设置前景。 - JPM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接