標籤:
1. TextView控制項是文本表示控制項,主要功能是向使用者展示文本的內容,它是不可編輯的,如設定標題;EditText控制項是編輯文本控制項,主要功能是讓使用者輸入文本的內容,它是可以編輯的。
每一個控制項都有著與之相應的屬性,通過選擇不同的屬性,給予其值,能夠實現不同的效果。
2. layout_width屬性值設定為wrap_content時,獲得的空間僅夠描繪自身,還有額外的空間。layout_weight的屬性值進行額外的空間分配。
如果layout_width="0dp",則只考慮layout_weight屬性值。
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/crime_date"
android:layout_weight="1"
/>
<CheckBox
android:id="@+id/crime_solved"
android:text="@string/crime_solved_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"/>
</LinearLayout>
如代碼:LinearLayout有兩個控制項,Button 和CheckBox.
第一步查看layout_width屬性值(豎直方向則查看layout_height)。因為設定為wrap_content時,獲得的空間僅夠描繪自身,還有額外的空間。
第二步LinearLayout依據layout_weight的屬性值進行額外的空間分配。兩個子組件屬性值同為1。因為均分了同樣大小的額外空間。若設Button的layout_weight的值為2,則將獲得2/3的額外空間,
CheckBox組件獲得剩餘的1/3。
布局TextView和EditText區別,layout_width和lay_weight區別--Android Studio