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

來源:互聯網
上載者:User

標籤:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.