首先说一下布局文件的道理,控件是不能置于控件之上的,控件只能置于容器之中。我们所常看见的,某图片上还有图片,这绝不是2个图片控件的叠加,而是底下的图片实际上作为了一个容器的背景图,而上面的图片可以作为控件置于该容器之中,看起来也就是图片之上有图片了。
下面就是一个"分享ImageButton"置于容器中的例子:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/base_background">
<RelativeLayout android:id="@+id/tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/main_bg">//@drawable/main_bg即"隐身微博"蓝色图片
<ImageButton android:id="@+id/share1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"//使分享按钮居右
android:background="@drawable/share1"/>//此处用android:background则显示效果如左图,如换用android:src则效果如右图
</RelativeLayout>
……
</RelativeLayout>