The weight (weight attribute) of LinearLayout_zhaojianand’s blog

Detailed explanation of weight (weight) attribute: ①The simplest usage: As shown in the picture: Implementation code: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android =”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” > <TextView android:layout_width=”fill_parent” android:layout_height=”0dp” android:background=”#ADFF2F” android:text=”weight is 1″ android:layout_weight=”1″/> <TextView android:layout_width=”fill_parent” android:layout_height=”0dp” android:background=”#DA70D6″ android:text=”weight is 2″ android:layout_weight=”2″/> To achieve the first 1:1 effect, you only need to put the weight of the two LinearLayouts separately Change it to 1 and 1. Usage summary: Divide the vertical direction according to the proportion: set the android:width attribute of the involved View to 0dp, and then set it to the android weight attribute to set the ratio; by analogy, for the horizontal direction, just Set android:height to 0dp, and then set the weight attribute! You can write a horizontal division of equal proportions to experience the simple usage! ②Detailed explanation of weight attribute: Of course, if we do not apply the above-mentioned method of setting 0dp, use wrap_content and match_parent directly , it is necessary to analyze the weight attribute, which is divided into two cases, wrap_content and match_parent! In addition, it depends on whether the orientation of LinearLayout is horizontal or vertical, which determines which direction is divided in equal proportions 1)wrap_content It’s relatively simple, it’s directly…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索