1 <?xml version="1.0" encoding="utf-8"?> 2 <!-- Copyright (C) 2007 The Android Open Source Project 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 --> 16 17 <!-- Demonstrates using a relative layout to create a form --> 18 19 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 20 android:layout_width="match_parent" 21 android:layout_height="wrap_content" 22 android:background="@drawable/blue" 23 android:padding="10dip"> 24 25 <!-- 26 TextView goes at the top left by default . 27 --> 28 <TextView 29 android:id="@+id/label" 30 android:layout_width="match_parent" 31 android:layout_height="wrap_content" 32 android:text="@string/relative_layout_2_instructions"/> 33 34 <!-- 35 Put the EditText field under the TextView 36 Also give it a standard background (the "android:" 37 part in @android:drawable/editbox_background 38 means it is system resource rather than 39 an application resource. 40 --> 41 <EditText 42 android:id="@+id/entry" 43 android:layout_width="match_parent" 44 android:layout_height="wrap_content" 45 android:background="@android:drawable/editbox_background" 46 android:layout_below="@id/label"/> 47 48 <!-- 49 The OK button goes below the EditText field. 50 It is also aligned to the right edge of the parent 51 (respecting the parent's padding). 52 The OK button comes first so the Cancel button 53 can be specified relative to the OK button. 54 --> 55 <Button 56 android:id="@+id/ok" 57 android:layout_width="wrap_content" 58 android:layout_height="wrap_content" 59 android:layout_below="@id/entry" 60 android:layout_alignParentRight="true" 61 android:layout_marginLeft="10dip" 62 android:text="@string/relative_layout_2_ok" /> 63 64 <!-- 65 The Cancel button is aligned with the top of 66 the OK button and positioned to the left of it. 67 Since the OK button has a left margin of 10, there 68 is some space between the two buttons. 69 --> 70 <Button 71 android:layout_width="wrap_content" 72 android:layout_height="wrap_content" 73 android:layout_toLeftOf="@id/ok" 74 android:layout_alignTop="@id/ok" 75 android:text="@string/relative_layout_2_cancel" /> 76 77 </RelativeLayout> 78 79