Adam Katz Adam Katz - 2 months ago 7
Android Question

Android LinearLayout start putting items from the right

I am trying to make a Linear layout which has 2 items, one item is an arrow and needs to fit on the right of the screen, the other item is an edit text that needs to fit the rest of the view. I have tried a bunch of ways to do this but none of them seem to work. My latest attempt is to use layout_weight but that is giving me issues of the arrow has too much area around it on bigger phones.

<LinearLayout
android:id="@+id/sendLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:weightSum="2"
android:paddingBottom="@dimen/scale_5dp"
android:layout_marginLeft="@dimen/scale_10dp"
android:layout_marginRight="@dimen/scale_10dp"
android:layout_weight="0.2">



<LinearLayout
android:layout_width='0dp'
android:layout_height="wrap_content"
android:layout_weight="1.7"
>


<com.heyjude.heyjudeapp.customview.EditRobotoRegular
android:id="@+id/editChatMsg"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@drawable/linear_back"
android:hint="Type your message..."
android:padding="@dimen/scale_5dp"
android:inputType="textMultiLine|textCapSentences|text"
android:textColor="#5f6060"
android:textColorHint="#5f6060"
android:textSize="@dimen/text_14"
android:imeOptions="actionSend"
/>
</LinearLayout>


<ImageButton
android:id="@+id/ivSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_chat_icon"
android:background="@android:color/transparent"
android:layout_weight="0.3" />

</LinearLayout>


Here is what it looks like as it currently is, as you can see there is too much space around the arrow

enter image description here

Answer

Try this one... and change the icon and text according to your requirements

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:gravity="bottom"
android:layout_gravity="bottom"
android:background="#cfd8dc"
android:layout_height="wrap_content">

<ImageButton
    android:id="@+id/send"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@android:drawable/ic_menu_send" />

<EditText
    android:id="@+id/text"
    android:paddingLeft="8dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Type your message"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@id/send" />
</RelativeLayout>

This will look like this

Comments