The difference between Android layout_gravity, Gravity, Layout_margin, padding

Source: Internet
Author: User

<linearlayout        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content"         Android : orientation= "Horizontal"        >        <imageview            android:layout_width= "Wrap_content"            android: layout_height= "Wrap_content"             android:src= "@drawable/ic_launcher"            />        <textview            android: text= "mobile phone anti-theft"            android:layout_width= "wrap_content"            android:layout_height= "wrap_content"/> </    Linearlayout>

  <LinearLayout>

<linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android: Layout_gravity= "Center_horizontal" <!---------------------> android:orientation= "Horizontal" > <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/ic_launcher" /> <textview android:text= "mobile phone anti-theft" Android: Layout_width= "Wrap_content" android:layout_height= "wrap_content"/> </LinearLayout>
<LinearLayout>

android:layout_gravity= "Center_horizontal" layout represents the relative parent control, the child control changes, and the gravity represents the content _center_horizontal

<LinearLayout>   
<linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android: Layout_gravity= "Center_horizontal" android:gravity= "center_vertical" android:orientation= "Horizontal" > <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/ic_launcher" /> <textview android:text= "mobile phone anti-theft" Android: Layout_width= "Wrap_content" android:layout_height= "wrap_content"/> </LinearLayout>
<LinearLayout>

Android:gravity= "center_vertical" Gravity relative to the content center_vertical, 1) If there is content on the button, then the content center_vertical

2) If there is a control under LinearLayout, then the control under LinearLayout center_vertical


<linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android: Layout_gravity= "Center_horizontal" android:gravity= "center_vertical" android:layout_margin= "50DP " android:orientation= "Horizontal" > <imageview android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/ic_launcher" /> <textview android:text= "mobile phone anti-theft" android:layout_width= "wrap_content" android:layout_height= "wrap_content"/ > </LinearLayout>
<LinearLayout>

android:layout_margin= "50DP" layout: Represents the relative parent control, and the child control changes. Margin: Represents the margin.

Layout_margin represents the margin with the parent control


<linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android: Layout_gravity= "Center_horizontal" android:gravity= "center_vertical" android:layout_margin= "50DP " android:orientation= "Horizontal" android:padding= "70DP" > <imageview android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:src= "@drawable/ic_launcher" / > <textview android:text= "mobile phone anti-theft" android:layout_width= "wrap_content" android:layout_ height= "Wrap_content"/> </LinearLayout>
<LinearLayout>

Android:padding= "70DP" indicates content padding

The difference between Android layout_gravity, Gravity, Layout_margin, padding

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.