There are millions of questions and answers in related to "layout_gravity Bottom/Top in LinearLayout" on stack overflow but I still haven't solved my problem.
I want to place my EditText which says "Please place me at the very top" at the very top, and TextView which says "Please place me at very bottom" at the very bottom. My dream is very basic but I cannot achieve it!!
Can anyone help me?
This is my XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="210dp"
android:background="@android:color/holo_green_light"
android:gravity="center_vertical"
android:orientation="vertical"
android:weightSum="1">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Please place me at very top" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/background_light"
android:text="TextView"
android:layout_weight="0.19" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="248dp"
android:layout_weight="0.70"
android:background="@color/colorAccent"
android:gravity="center_vertical"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_gravity="top"
android:text="Button" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.16"
android:background="@android:color/background_light"
android:text="Please place me at very bottom" />
</LinearLayout>
</LinearLayout>
And this is my output:
You have set gravity bottom for your second linear layout to place the views at the bottom.
change this line at first LinearLayout:
To:
change this line at Second LinearLayout:
To:
Note: Avoid using nested weights it will slow down the performance.