简体   繁体   中英

How to align a button bottom with multiline edit text in linear layout Android

I'd like to align a Button and a multiLine EditText at the bottom of the screen. They should both be beside each other. Both of these are currently in a LinearLayout . How do I do this?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" 
    android:orientation="vertical"
    android:weightSum="2">

    <LinearLayout
        android:id="@+id/linearlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#F5F5F5"
        android:orientation="horizontal" 
       >

        <TextView
            android:id="@+id/Text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="To:"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/To"
            android:layout_width="153dp"
            android:layout_height="fill_parent"
            android:layout_weight="0.86"
            android:inputType="phone" />

        <Button
            android:id="@+id/Browse"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:text="+" />
    </LinearLayout>

     <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"

            android:layout_below="@+id/linearlayout" />

<!-- 
            <TextView 
            android:id="@+id/awain"
            android:layout_width="wrap_content"
          android:layout_height="wrap_content"
            android:layout_below="@+id/linearlayout" 
            android:text="Listview"

            /> -->




    <RelativeLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"


        >
           <LinearLayout
            android:orientation="horizontal"

            android:layout_width="fill_parent"
            android:layout_height="wrap_content">


            <EditText
                android:id="@+id/Message"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"

                android:inputType="textCapSentences|textMultiLine"
                android:maxLength="2000"
                android:maxLines="5"  />

      <Button
                android:id="@+id/send"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:minWidth="150dp"
                android:text="Send"
                android:layout_marginBottom="0dp"
                android:layout_alignParentBottom="true">

            </Button>





      </LinearLayout>


    </RelativeLayout>













</RelativeLayout>
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

<EditText 
    android:layout_height="wrap_content"
    android:layout_width="200dp"
    android:gravity="top"
    android:lines="3"
    android:layout_gravity="bottom"/>

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:text="test"/>


</LinearLayout>

you have to use the relative layout as parent of your Linerlayout

See the example here..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/edittextid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Your edit text"
        android:maxLines="3" />

    <Button
        android:id="@+id/buttonid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
  </LinearLayout>

</RelativeLayout>

@user2552435

You use RelativeLayout, change RelativeLayout to LinearLayout

<RelativeLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM