UI layout, especially complex multi-LinearLayout nesting, is often plagued by some small issues for the last half of the day. For example, when using ImageView today, You Want To center it, however, no matter how you set the layout_gravity attribute, the effect cannot be achieved. Part of the Code is as follows:
[Java]
Copy codeThe Code is as follows: <LinearLayout
Android: layout_width = "wrap_content"
Android: layout_height = "fill_parent"
Android: orientation = "vertical"
Android: layout_weight = "1"
Android: padding = "20dp">
<LinearLayout
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: orientation = "horizontal">
<LinearLayout
Android: layout_width = "108dp"
Android: layout_height = "108dp"
Android: orientation = "vertical"
Android: background = "# 3399ff">
<ImageView
Android: layout_width = "64dp"
Android: layout_height = "64dp"
Android: src = "@ drawable/menu_icon _ mail"
Android: layout_gravity = "center"/>
</LinearLayout>
As a result, you can find information to find a solution. It turns out that the attribute of the parent class view is not set. You can set the parent Class View to the Center side, that is, android: gravity = "center ":
[Java]Copy codeThe Code is as follows: <LinearLayout
Android: layout_width = "wrap_content"
Android: layout_height = "fill_parent"
Android: orientation = "vertical"
Android: layout_weight = "1"
Android: padding = "20dp">
<LinearLayout
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: orientation = "horizontal">
<LinearLayout
Android: layout_width = "108dp"
Android: layout_height = "108dp"
Android: orientation = "vertical"
Android: gravity = "center"
Android: background = "# 3399ff">
<ImageView
Android: layout_width = "64dp"
Android: layout_height = "64dp"
Android: src = "@ drawable/menu_icon _ mail"
Android: layout_gravity = "center"/>
</LinearLayout>
There are usually very few details about the UI design, which is a very simple problem. Sometimes it will bother you for a while. However, if you have a lot of design experience on your own, it will be easy to solve it!