一起学Android之Layout

移动开发 作者: 2024-08-24 15:00:01
本文简述在Android开发中布局的简单应用,属于基础知识,仅供学习分享使用。
 
  • android:layout_alignParentTop 是否位于父控件的部(true 或 false)
  • android:layout_alignParentBottom 是否位于父控件的部(true 或 false)
  • android:layout_alignParentLeft 是否位于父控件的边(true 或 false)
  • android:layout_alignParentRight 是否位于父控件的边(true 或 false)
  • android:layout_centerInParent 是否位于父控件的中心(true 或 false)
  • android:layout_toLeftOf 位于指定控件的边(值为控件的ID)
  • android:layout_toRightOf 位于指定控件的边(值为控件的ID)
  • android:layout_above 位于指定控件的边(值为控件的ID)
  • android:layout_below 位于指定控件的边(值为控件的ID)
 
  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout
  3     xmlns:android="http://schemas.android.com/apk/res/android"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:layout_width="match_parent"
  6     android:layout_height  7     android:paddingBottom="@dimen/activity_vertical_margin"
  8     android:paddingLeft="@dimen/activity_horizontal_margin"
  9     android:paddingRight 10     android:paddingTop 11     android:orientation="vertical"
 12     tools:context="com.hex.demolayout.LinearActivity">
 13     TextView
 14         android:id="@+id/tv_text"
 15         android:text="@string/tv_name"
 16         android:textSize="20dp"
 17         android:layout_marginTop="5dp"
 18         android:textColor="@color/colorBlue"
 19         android:layout_width 20         android:layout_height="wrap_content"/>
 21     EditText
 22         ="@+id/txt_name"
 23         android:hint="@string/hint_name"
 24  25  26      27         ="@+id/tv_age"
 28 ="@string/tv_age"
 29  30  31  32  33  34      35         ="@+id/txt_age"
 36  37  38  39      40         ="@+id/tv_sex"
 41 ="@string/tv_sex"
 42  43  44  45  46  47     RadioGroup
 48         ="@+id/rg_sex"
 49  50         android:orientation="horizontal"
 51  52  53         RadioButton
 54             ="@+id/rb_male"
 55             android:text="@string/male"
 56             android:textSize="20sp"
 57             android:checked="true"
 58             android:layout_width="wrap_content"
 59             android:layout_height 60          61             ="@+id/rb_female"
 62  63 ="@string/female"
 64             android:layout_marginLeft="30dp"
 65  66  67     </RadioGroup 68      69         ="@+id/tv_love"
 70 ="@string/love"
 71  72  73  74  75  76      77         android:layout_width 78  79 ="10dp"
 80 ="horizontal" 81         CheckBox
 82             ="@+id/ck_basketball"
 83 ="@string/basketball"
 84  85  86  87          88             ="@+id/ck_football"
 89 ="@string/football"
 90  91  92  93  94          95             ="@+id/ck_game"
 96 ="@string/game"
 97  98  99 100 101     LinearLayout102     103         ="@+id/tv_school"
104 ="@string/school"
105 106 107 108 109 110     111         ="@+id/txt_school"
112 ="@string/hint_school"
113 114 115     116         ="@+id/tv_addr"
117 ="@string/addr"
118 119 120 121 122 123     124         ="@+id/txt_addr"
125 ="@string/hint_addr"
126 127 128     Button
129         ="@+id/bn_submit"
130 ="@string/bn_submit"
131 132 133 134 >
View Code
RelativeLayout
="com.hex.demolayout.MainActivity" 12 
="@+id/tv_title"
        android:layout_centerHorizontal        android:layout_alignParentTop 21         android:layout_margin="3dp"
 22 ="@string/nine_tip" 23      24         ="@+id/tv_center"
="@string/center"
 26  27         android:onClick="open"
="@color/colorRed"
        android:layout_centerInParent 33      34         ="@+id/tv_east"
 35 ="@string/east"
 39         android:layout_alignParentLeft 40         android:layout_centerVertical 43      44         ="@+id/tv_west"
="@string/west"
 47  48         android:layout_alignParentRight 53      54         ="@+id/tv_north"
="@string/north"
        android:layout_alignParentBottom 60  61  63      64         ="@+id/tv_south"
="@string/south"
 67  68  69         android:layout_below="@id/tv_title"
 73      74         ="@+id/tv_east_south"
="@string/east_south"
 76  77  81  82  83      84         ="@+id/tv_west_south"
="@string/west_south"
 87  88  93      94         ="@+id/tv_east_north"
 95 ="@string/east_north"
101 ="@+id/tv_west_north"
="@string/west_north"
110 111 112     113         ="@+id/tv_xun"
="@string/xun"
115 116 ="@color/colorGreen"
="@id/tv_east_south"
121     122         ="@+id/tv_li"
123 ="@string/li"
124 ="@id/tv_south"
128 129 131     132         ="@+id/tv_kun"
="@string/kun"
134 135 136 137 ="@id/tv_west_south"
138 139 140 141     142         ="@+id/tv_zen"
143 ="@string/zen"
144 145 146 147         android:layout_toRightOf="@id/tv_east"
148 149 150 151     152         ="@+id/tv_dui"
153 ="@string/dui"
154 155 156 157         android:layout_toLeftOf="@id/tv_west"
158 159 160 161     162         ="@+id/tv_gen"
163 ="@string/gen"
164 165 166 167         android:layout_above="@id/tv_east_north"
168 169 170     171         ="@+id/tv_kan"
172 ="@string/kan"
173 174 175 ="@id/tv_north"
176 177 178 179 180     181         ="@+id/tv_qan"
182 ="@string/qan"
183 184 185 186 ="@id/tv_west_north"
187         android:layout_alignRight188 189 190     191         ="@+id/tv_mu"
192 ="@string/mu"
193 194 195 196 ="@id/tv_xun"
197 198 199     200         ="@+id/tv_huo"
201 ="@string/huo"
202 203 204 205 ="@id/tv_li"
206 207 208 209     210         ="@+id/tv_tu"
211 ="@string/tu"
212 213 214 215 ="@id/tv_kun"
216 217 218 219     220         ="@+id/tv_mu2"
221 222 223 224 225 ="@id/tv_zen"
226         android:layout_alignLeft227 228 229     230         ="@+id/tv_tu2"
231 232 233 234 235 ="@id/tv_center"
236 237 238 239     240         ="@+id/tv_jin"
241 ="@string/jin"
242 243 244 245 ="@id/tv_dui"
246 247 248 249     250         ="@+id/tv_tu3"
251 252 253 254 255 ="@id/tv_gen"
256 257 258     259         ="@+id/tv_shui"
260 ="@string/shui"
261 262 263 ="@id/tv_kan"
264 265 266 267 268     269         ="@+id/tv_jin2"
270 271 272 273 ="@id/tv_qan"
274 275 276 277 278 RelativeLayout>
View Code
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_67878.html
一起学Android之Layout