2

I have the following code -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:ignore="HardcodedText">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2"/>

</LinearLayout>

It gives me this output -

enter image description here

Now including the code -

android:gravity="fill"

or

android:gravity="fill_horizontal"

or

android:gravity="fill_vertical"

doesn't bring about any change in the output.

As I understand from some tutorials -

  1. fill is used to fill the entire container both horizontally and vertically

  2. fill_horizontal is used to fill the entire container horizontally

  3. fill_vertical is used to fill the entire container vertically

Here, the container of LinearLayout is supposed to be the whole screen as layout_width and layout_height is set as match_parent

So why the gravity codes fail to have any impact?

Payel Senapati
  • 1,134
  • 1
  • 11
  • 27

0 Answers0