Ali
Ali

Reputation: 9994

Footer view as RelativeLaout

I have a RelativeLayout which includes following RelativeLayout:

<RelativeLayout
        android:id="@+id/buttons_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingTop="10dip" >

        <Button
            android:id="@+id/day_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="day"
            android:layout_alignParentLeft="true"
            android:textSize="14sp"/>


        <Button
            android:id="@+id/month_button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="month"
            android:layout_alignParentRight="true"
            android:textSize="14sp"/>

        <EditText
            android:id="@+id/week_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/day_button"
            android:layout_toLeftOf="@id/month_button1"
            android:maxLines="5"
            android:minLines="1"
            android:textSize="16sp"
            android:layout_marginBottom="15dp"/>
    </RelativeLayout>

This layout will be shown as a footer for the page. As you see the maxLines for EditText is 5. When the line size is more than 2 in EditText, buttons around it start to move a bit up. I want buttons stick to the end of page and do not move. Any solution?

I tried adding android:layout_alignParentBottom="true" for buttons but it did not work.

Upvotes: 0

Views: 46

Answers (2)

Oleksii K.
Oleksii K.

Reputation: 5419

Try to add android:layout_alignParentBottom="true" for all child elements.

It works at least in Android Studio.

UPDATED

Add android:layout_alignBottom="@+id/week_button" for both buttons.

enter image description here

Upvotes: 1

Budius
Budius

Reputation: 39846

it sounds to be as a bug in the UI framework, but there's usually work around to achieve the same visual effect.

For example, replacing this RelativeLayout you show in the XML to a LinearLayout with orientation="horizontal" should give the same visual effect.

pseudo code

<LinearLayout horizontal>
   <Button wrap_content layout_gravity=bottom/>
   <EditText width=0dp weight=1/> // makes EditText fill remaining space
   <Button wrap_content layout_gravity=bottom/>
</LinearLayout>

Upvotes: 0

Related Questions