0

I'm trying to split the vertical space between views evenly using layout_weight but from some reason it doesn't work. I followed this answer and still the views's spaces aren't effected by that. What am I doing wrong?

<LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <Space
                    android:layout_width="1dp"
                    android:layout_height="0dp"
                    android:layout_weight="1" >
                </Space>

                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <AutoCompleteTextView
                        android:background="@drawable/rounded_corners_white"
                        android:id="@+id/email"
                        android:paddingEnd="16dp"
                        android:paddingStart="16dp"
                        android:layout_marginRight="16dp"
                        android:layout_marginLeft="16dp"
                        android:layout_height="40dp"
                        android:layout_width="match_parent"
                        android:inputType="textEmailAddress"
                        android:maxLines="1"
                        android:singleLine="true" />

                </android.support.design.widget.TextInputLayout>

                <Space
                    android:layout_width="1dp"
                    android:layout_height="0dp"
                    android:layout_weight="1" >
                </Space>

                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_marginRight="16dp"
                    android:layout_marginLeft="16dp"
                    android:paddingEnd="16dp"
                    android:paddingStart="16dp"
                    android:layout_height="40dp"
                    android:background="@drawable/rounded_corners_white"
                    android:imeActionId="@+id/login"
                    android:imeActionLabel="@string/action_sign_in_short"
                    android:imeOptions="actionUnspecified"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true" />
                </android.support.design.widget.TextInputLayout>

                <Space
                    android:layout_width="1dp"
                    android:layout_height="0dp"
                    android:layout_weight="1" >
                </Space>

                <View
                    android:layout_marginTop="30dp"
                    android:layout_marginBottom="30dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_width="match_parent"
                    android:layout_height="3dp"
                    android:background="@drawable/rounded_corners_white" />

                <Space
                    android:layout_width="1dp"
                    android:layout_height="0dp"
                    android:layout_weight="1" >
                </Space>

                <Button
                    android:id="@+id/sign_in_button"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginLeft="16dp"
                    style="?android:textAppearanceSmall"/>
            </LinearLayout>

UPDATE: if image is not shown (https://i.stack.imgur.com/MQaLm.png) [graphic explanation

Community
  • 1
  • 1
ben
  • 1,064
  • 3
  • 15
  • 29
  • 1
    can you put your screen shot which you want to develop? – Vishal Patoliya ツ Jul 06 '16 at 13:40
  • Please explain further what you're trying to accomplish, and what exactly isn't working as expected. From what I can tell from your description, that layout will do what you want. – Mike M. Jul 06 '16 at 13:53
  • That's what that layout will do. You have one space at the top, a space between each `View`, and they will all be equal height. To check, you can temporarily change the ``s to ``s, set their `layout_width`s to `match_parent`, and give them `background` colors. Btw, I think you mean vertical space. – Mike M. Jul 06 '16 at 14:16
  • I have tried your code in xml file and don't see any problems. The items seem to be spaced equally. What needs to be solved? – Marat Jul 06 '16 at 14:26
  • So, your specific problem is that it's not taking up the entire screen vertically? – Daniel Nugent Jul 06 '16 at 15:05

1 Answers1

-1

Just add below line to your linearlayout:

android:weightSum="4"
Dhruvi
  • 1,971
  • 2
  • 10
  • 18