如何在LinearLayout中设置居中

如果想要在LinearLayout中设置居中,需要用到gravity

android:gravity:   takes care of its children

android:layout_gravity:  takes care of itself.

    android:id="@+id/activity_main"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:gravity="center_horizontal"

    tools:context="com.example.android.jlapp.MainActivity"/>

你可能感兴趣的:(如何在LinearLayout中设置居中)