To create a child View with a proportional size, you can set the width and height of LinearLayout to fill_parent, set the width or height of the Child View to 0, and then set different weights (weight) for the child View ), in this way, the size of the View is proportional to the weight.
In this example, horizontal LinearLayout and LinearLayout android: layout_width = "match_parent" are used to indicate that the entire screen width will be used.
For several subviews of LinearLayout, define their width as 0, android: layout_width = "0dip", and then use layout_weight to specify the width ratio for each View, in this example, the same weight is used for each TextView. Therefore, the four textviews have the same width. In this way, the height of TextView with long text displayed is changed to multiple rows.
Copy codeThe Code is as follows: <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android?android:orientation=horizontal"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">
<TextView
Android: background = "@ drawable/red"
Android: layout_width = "0dip"
Android: layout_height = "match_parent"
Android: layout_weight = "1 ″
Android: text = "@ string/linear_layout_7_small"/>
<TextView
Android: background = "@ drawable/green"
Android: layout_width = "0dip"
Android: layout_height = "match_parent"
Android: layout_weight = "1 ″
Android: text = "@ string/linear_layout_7_big"/>
<TextView
Android: background = "@ drawable/blue"
Android: layout_width = "0dip"
Android: layout_height = "match_parent"
Android: layout_weight = "1 ″
Android: text = "@ string/linear_layout_7_small"/>
<TextView
Android: background = "@ drawable/yellow"
Android: layout_width = "0dip"
Android: layout_height = "wrap_content"
Android: layout_weight = "1 ″
Android: text = "@ string/linear_layout_7_wrap"/>
</LinearLayout>