My requirement is to achieve this in LinearLayout. It is having only one child view. In horizontal orientation, a button needs to be at center horizontal, if layout_gravity is set. my layout xml is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="200dp"
android:background="#ffff00"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Button" />
</LinearLayout>
But the result is like below image
What i am expecting is, when the layout_gravity is set to center_horizontal , the button center to the horizontal. Why this is not working