Reputation: 3430
Here's the problem parent and it's contents from my xml file:
<RelativeLayout
android:id="@+id/group_chat_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:background="@drawable/transparent_background2" >
<TextView
android:id="@+id/send_msg_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@drawable/transparent_background2"
android:text="Send" />
</RelativeLayout>
The parent is clearly not wrapping the contents.
If I remove the alignParentBottom="true"
attribute from the child, it looks perfect.
However I need this particular child to stay anchored to the bottom because I have a multiline edittext view in this same parent (I did not include it since this problem still occurs with the multiline edittext commented out). As the edittext expands with more input from the user, the Send button should stay anchored to the bottom of the parent. Here's what it should look like (multi-lined EditText not included):
Upvotes: 4
Views: 1691
Reputation: 53
That's a limitation for a relative layout. See verified answer in this link
I'm doing the same objective and came up with this solution:
<RelativeLayout
android:id="@id/comment_input_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/light_gray"
android:padding="4dp">
<LinearLayout
android:layout_width="match_parent"
android:gravity="bottom"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@id/comment_input_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/label_add_a_comment"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="6"
android:scrollbars="vertical" />
<Button
android:id="@id/send_comment_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_send" />
</LinearLayout>
<ProgressBar
android:id="@id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
the android:layout_weight="1"
causes the editText to take up the free space available as long as the other siblings doesn't have weight.
Hope this helps.
Upvotes: 3