Android layout_gravity Bottom/Top in LinearLayout -


there millions of questions , answers in related "layout_gravity bottom/top in linearlayout" on stack overflow still haven't solved problem.

i want place edittext says "please place me @ top" @ top, , textview says "please place me @ bottom" @ bottom. dream basic cannot achieve it!!

can me?

this 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 @ 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 @ bottom" />      </linearlayout>  </linearlayout> 

and output:

enter image description here

if linearlayout isn't working, don't force use it.

  1. nested linearlayouts , weights bad performance.

  2. relativelayout (or constraintlayout) naturally meant place things @ anchor points of viewgroups

i assume want text , button centered based on other attributes

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"               android:layout_width="match_parent"               android:layout_height="match_parent"               android:orientation="vertical"               android:weightsum="2">       <relativelayout             android:layout_width="match_parent"             android:layout_height="0dp"             android:background="@android:color/holo_green_light"             android:layout_weight="1">          <edittext                 android:id="@+id/edittext"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:ems="10"                 android:layout_alignparenttop="true"                 android:inputtype="textpersonname"                 android:text="please place me @ top" />          <textview                 android:id="@+id/textview"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_centerinparent="true"                 android:background="@android:color/background_light"                 android:text="textview" />      </relativelayout>      <relativelayout             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="1"             android:background="@android:color/holo_red_light"             android:orientation="vertical">          <button                 android:id="@+id/button"                 android:layout_width="match_parent"                 android:layout_height="62dp"                 android:layout_centerinparent="true"                 android:text="button"/>          <textview                 android:id="@+id/textview2"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_alignparentbottom="true"                 android:background="@android:color/background_light"                 android:text="please place me @ bottom"/>      </relativelayout>  </linearlayout> 

alternatively, need android:gravity="bottom" on second linearlayout, views within @ bottom.

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"               android:layout_width="match_parent"               android:layout_height="match_parent"               android:orientation="vertical"               android:weightsum="1">      <!-- top gravity -->     <linearlayout             android:gravity="top"             android:layout_width="match_parent"             android:layout_height="0dp"             android:background="@android:color/holo_green_light"             android:orientation="vertical"             android:layout_weight="0.5">          <edittext                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:text="please place me @ top"/>          <textview                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:background="@android:color/background_light"                 android:text="textview"/>      </linearlayout>      <!-- bottom gravity -->     <linearlayout             android:gravity="bottom"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="0.50"             android:background="@android:color/holo_red_light"             android:orientation="vertical">          <button                 android:layout_width="match_parent"                 android:layout_height="62dp"                 android:text="button"/>          <textview                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:background="@android:color/background_light"                 android:text="please place me @ bottom"/>      </linearlayout>  </linearlayout> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -