Android imageview image center tips

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.