Android线性布局之layout_gravity和gravity区别

来源:互联网 发布:怎么绑定域名到空间 编辑:程序博客网 时间:2024/04/29 16:28

android:layout_gravity:表示子元素位于父元素的位置

 android:gravity:表示控件内部的元素位于该控件的位置

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:background="#ccccff"        android:gravity="right" >        <Button            android:id="@+id/button1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="Button" />    </LinearLayout></LinearLayout>


效果图如下



0 0