习惯了Delphi/VB等RAD的拖放布局,使用Android的布局管理器还真不习惯.
例如要实现下面的界面布局:
则需要如下设置:
1 <LinearLayout 2 android:layout_width="wrap_content" 3 android:layout_height="wrap_content" 4 android:orientation="horizontal" > 5 6 <TextView 7 android:id="@+id/textView1" 8 android:layout_width="wrap_content" 9 android:layout_height="wrap_content" 10 android:text="编码" /> 11 12 <EditText 13 android:id="@+id/editText1" 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 android:layout_weight="2" 17 android:ems="10" > 18 19 <requestFocus /> 20 </EditText> 21 22 23 <TextView 24 android:id="@+id/textView2" 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 android:text="名称" /> 28 29 30 31 32 33 <EditText 34 android:id="@+id/editText2" 35 android:layout_width="wrap_content" 36 android:layout_height="wrap_content" 37 android:layout_weight="1" 38 android:ems="10" > 39 40 <requestFocus /> 41 </EditText> 42
43 </LinearLayout>
这里比较重要的属性是:
android:layout_weight
该属性是设置比重的,但设置好像是反的,TextView就不要设置这个属性了,要不然显示会比较令人郁闷的.