android - Element relative height in layout -
I have seen that elements of width can be set to the width of the screen one Using relative layout (code showing only relevant properties):
& lt; LinearLayout & gt; & Lt; ImageView Android: layout_width = "0dp" Android: layout_weight = ".40" /> & Lt; / ImageView & gt; & Lt; TextView Android: layout_width = "0dp" android_layout_weight = ". 60" /> & Lt; / LinearLayout & gt;
But ... apparently it can not be done with the same trick to specify proportionally height of the same element. If I try to define layout_hett of 0dp, eclipse complains if I want a picture with a caption, what should I do, where the image raises 40% of the height of the screen and the caption below becomes 60% is? You can actually assign loads for both horizontal and vertical orientation of a linear line.
Horizontal orientation example:
& lt; LinearLayout Xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: orientation = "horizontal" & gt; & Lt; ImageView Android: layout_width = "0dp" Android: layout_height = "match_parent" android: layout_weight = ".40" /> And lieutenant; TextView Android: Layout_Wind = "0 DP" Android: Layout_Height = "Match_Partent" Android: Layout_Vet = ".60" /> & Lt; / LinearLayout & gt;
Workbench orientation example:
& lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: Layout_width = "match_parent" Android: layout_height = "match_parent" Android: orientation = "vertical" & gt; & Lt; ImageView Android: layout_width = "match_parent" android: layout_height = "0dp" Android: layout_weight = ".40" /> & Lt; TextView Android: layout_width = "match_perrent" android: layout_heahat = "0dpp" android: layout_weight = ".60" /> & Lt; / LinearLayout & gt;
On the one hand, it is useful to know that you do not need to specify the floating point number for weight. The Android bus will add all the weight and then the totals for each get the percentage for each. That's why layout_weights will be okay to use 4 and 6, respectively.
Comments
Post a Comment