<EditText android:id="@+id/text"
android:layout_width="fill_parent"//因为这儿已经水平占据了空间,图片被挤出去了
android:layout_height="wrap_content"
android:layout_marginLeft="17px"
android:layout_marginRight="40px"
android:background="#FFFFFF"
android:layout_below="@id/register"
/>下面这个可以实现:<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/register" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:text="Register"></TextView>
<EditText android:id="@+id/text" android:layout_width="150px"
android:layout_height="wrap_content" android:layout_marginLeft="17px"
android:layout_marginRight="40px" android:background="#FFFFFF"
android:layout_below="@id/register"/>
<ImageView android:src="@drawable/icon" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@id/text" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/register" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:text="Register"></TextView>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/register" android:layout_alignParentRight="true" />
<EditText android:id="@+id/text" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="defaultContent"
android:background="#FFFFFF" android:layout_toLeftOf="@id/imageView"
android:layout_below="@id/register"/>
</RelativeLayout>
效果图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/register" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:text="Register"></TextView>
<ImageView android:src="@drawable/icon" android:id="@+id/imageView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/register" android:layout_alignParentRight="true" />
<EditText android:id="@+id/text" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="defaultContent"
android:background="#FFFFFF" android:layout_toLeftOf="@id/imageView"
android:layout_alignBottom="@id/imageView"/>
</RelativeLayout>
这次练习我发现RelativeLayout在设置参考位置时,(left | right) 和 (top | bottom)两者之间必须都有定位,否则默认位置贴近于屏幕的(0,0)