<?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"
>
<!--定义该组件位于父容器中间 -->
<TextView
android:id="@id/view01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_centerInParent="true"
/>
<!-- 定义该图view02在第一个图view01的上边,与图view01的左边界对齐 -->
<TextView
android:id="@id/view02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_above="@id/view01"
android:layout_alignLeft="@+id/view01"
/>
<!-- 定义该图view03在第一个图view01的下边,与图view01的左边界对齐 -->
<TextView
android:id="@id/view03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_below="@id/view01"
android:layout_alignLeft="@+id/view01"
/>
<!-- 定义该图view04在第一个图view01的左边,与图view01的上边界对齐 -->
<TextView
android:id="@id/view04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_toLeftOf="@id/view01"
android:layout_alignTop="@+id/view01"
/>
<!-- 定义该图view05在第一个图view01的右边,与图view01的上边界对齐 -->
<TextView
android:id="@id/view05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_toRightOf="@id/view01"
android:layout_alignTop="@+id/view01"
/>
</RelativeLayout></span></strong>
为了达到梅花效果,一顿的调,一顿的调, android:id="@id/view01"这句话总是报错,gen/R.java中的id类里边总是加不上去view01到view05这几个变量。不是第一次了,对这个有点迟钝,“+”,切记,切记!!!正确的是这样:android:id="@+id/view01"
正确的代码:
<?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"
>
<!--定义该组件位于父容器中间 -->
<TextView
android:id="@+id/view01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_centerInParent="true"
/>
<!-- 定义该图view02在第一个图view01的上边,与图view01的左边界对齐 -->
<TextView
android:id="@+id/view02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_above="@id/view01"
android:layout_alignLeft="@+id/view01"
/>
<!-- 定义该图view03在第一个图view01的下边,与图view01的左边界对齐 -->
<TextView
android:id="@+id/view03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_below="@id/view01"
android:layout_alignLeft="@+id/view01"
/>
<!-- 定义该图view04在第一个图view01的左边,与图view01的上边界对齐 -->
<TextView
android:id="@+id/view04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_toLeftOf="@id/view01"
android:layout_alignTop="@+id/view01"
/>
<!-- 定义该图view05在第一个图view01的右边,与图view01的上边界对齐 -->
<TextView
android:id="@+id/view05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/leaf"
android:layout_toRightOf="@id/view01"
android:layout_alignTop="@+id/view01"
/>
</RelativeLayout>