最近犯过几次这样的错。
在RelativeLayout布局里,有两个控件,如图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4CBAEB">
<TextView
android:id="@+id/tv_xiala"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="下拉刷新"
android:textColor="@color/white"
android:textSize="30sp" />
<ImageView
android:id="@+id/img_jiantou"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
android:layout_toLeftOf="@id/tv_xiala"
android:background="@drawable/head_me" />
</RelativeLayout>
第一个控件是 TextView,id是tv_xiala
第二个控件是ImageView,id是img_jiantou
因为在第二个控件里用到了第一个控件的id
android:layout_toLeftOf=”@id/tv_xiala”
所以第二个控件必须写在第一个控件的下边,因为安卓读取布局的时候是从上往下读的,如果放在上面就会出现找不到id的情况啦。
所以如果用到
android:layout_toLeftOf
android:layout_toRightOf=””
android:layout_above=””
android:layout_below=””
这些属性的时候要小心啦。虽然不是什么大问题,但是记录一下,巩固一下知识吧。