如何在android中的图像上制作相框?

时间:2014-03-26 13:21:52

标签: android image

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_launcher" />
 </RelativeLayout>

enter image description here

此处较小的图像位于较大图像的顶部。我需要相同尺寸的图片,但较大的图像应该在较小的图像上。实际上我想制作相框应用程序。较大的图像是我的相框。较小的图像是我的相框应该出现的照片。但在我的应用程序中,照片出现在相框上。

我需要完全相反。请帮帮我。

3 个答案:

答案 0 :(得分:2)

使用LayerList:

制作3个文件:LayerList包含正确顺序的帧和照片:1 - 照片,2帧。

<强> RES /抽拉/ photoframe.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/pf_photo" />
    <item android:drawable="@drawable/pf_frame" />
</layer-list>

照片:

<强> RES /抽拉/ pf_photo.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_horizontal|center_vertical"
    android:src="@drawable/photo"
    android:dither="true"
    android:antialias="true"
/>

框架:

<强> RES /抽拉/ pf_frame.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_horizontal|center_vertical"
    android:src="@drawable/frame"
    android:dither="true"
    android:antialias="true"
/>

最后,使用LayerList作为RelativeLayout的背景:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/photoframe"
>
</RelativeLayout>

现在看看它是如何简化的。

任何带有透明孔的框架都可以解决问题(这里很好用,就是使用9补丁,以节省空间)

因此,如果您决定对该帧使用9补丁,

res / drawable / photoframe.xml 将成为:

<?xml version="1.0" encoding="utf-8"?>
<nine-patch
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_horizontal|center_vertical"
    android:src="@drawable/frame"
    android:dither="true"
    android:antialias="true"
/>

我得出了这个结果:

enter image description here

在res / drawable文件夹中使用这个9补丁

<强> frame.9.png

enter image description here

和res / drawable / xxhdpi文件夹中的这张照片

<强> photo.jpg

enter image description here

答案 1 :(得分:0)

使用此

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

<ImageView
android:id="@+id/imageView1"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />

  <ImageView
  android:id="@+id/imageView2"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentRight="true"
  android:layout_below="@+id/imageView1"
  android:layout_toRightOf="@+id/imageView1" 
  android:src="@drawable/ic_launcher" />
</RelativeLayout>

答案 2 :(得分:0)

噪音生成器(https://stackoverflow.com/a/22662631/5003906)提供的代码工作正常。但代码

<?xml version="1.0" encoding="utf-8"?>
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_horizontal|center_vertical"
android:src="@drawable/frame"
android:dither="true"
android:antialias="true" />

应放在pf_frame.xml文件中。

PS:很抱歉把它写成另一个答案,因为我没有足够的声誉来发表评论。