在RelativeLayout里面各个layout之间是可以叠加的,如何将一个控件对齐显示到另一个控件上呢?这就是我要说的Layout_alignXXX的工作。
就用layout_alignTop
来试试吧,当然还有layout_alignParentXXX这一系列的,只要会使用一个其他的就不存在太大问题了。
我们的代码是在ImageView上面显示一行字,这一行字最为ImageView的标题。
显示效果图:
就是Show top on title这一行。
最后上代码:
<?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/title"
android:src="@mipmap/ic_header_stub"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:textColor="@color/white"
android:gravity="center"
android:layout_alignTop="@id/title"
android:layout_alignParentLeft=""
android:text="Show top on title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>