简体   繁体   中英

android:layout_below doesn't seem to work

Using Xamarin in Visual Studio 2015 I am trying to edit the Main.axml file. in the file I have the TextView item:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/relativeLayout1" >
<TextView
    android:text="Search By Postal Code"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/PostalCodeSearchLabel"
    android:layout_margin="10dp" />
  <EditText
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/PostalCodeSearchLabel"
android:id="@+id/zipCodeEntry"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:width="165dp" />
      <Button
    android:id="@+id/ok"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/zipCodeEntry"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="10dp"
    android:text="OK" />
</RelativeLayout>

But the lines "layout_below" shows as invalid and the item doesn't display properly. All the examples I've read show this as being a valid parameter but it doesn't work. Why?

It seems to be a simple matter of saving my changes. When switching back to the designer after making changes in the source mode you have to save the changes before the designer will render properly.

You have to define the EditText after the view want it to go below.

<!-- Your view here -->

<EditText
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ZipCodeSearchLabel"
android:id="@+id/zipCodeEntry"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:width="165dp" />

If you reference an element by id- @id/foo but the element comes after the reference in xml then it won't work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM