布局TextView和EditText區別,layout_width和lay_weight區別--Android Studio


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。








免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM