4

I have a few layouts where I want to inlcude/> a bottom bar that contains two buttons. Pretty simple huh? Well, I am having issues getting this acomplished as the buttons are being set to the top of the View regardless of the parameters I set for it.

Here's how it currently looks.

Here's the actual merge code:

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

<View
    android:id="@+id/divider"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="?android:attr/dividerHorizontal" />

<LinearLayout
    android:id="@+id/button_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="?android:attr/dividerVertical"
    android:orientation="horizontal"
    android:showDividers="middle" >

    <Button
        android:id="@+id/left_button"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/cancel" />

    <Button
        android:id="@+id/right_button"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/complete" />
</LinearLayout>

Here's one of the layouts that includes it:

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

<TextView
    android:id="@+id/register_title_two"
    style="?android:attr/listSeparatorTextViewStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_margin="8dp"
    android:padding="8dp"
    android:text="@string/i_want_to"
    android:textColor="@android:color/holo_blue_dark" />

<RadioGroup
    android:id="@+id/extend_delete_alert_group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/register_title_two" >

    <RadioButton
        android:id="@+id/delete_alerts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:minHeight="32dp"
        android:padding="8dp"
        android:text="@string/delete_alerts"
        android:textSize="14sp" />

    <RadioButton
        android:id="@+id/extend_alerts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:minHeight="32dp"
        android:padding="8dp"
        android:text="@string/extend_alerts"
        android:textSize="14sp" />
</RadioGroup>

<include
    android:id="@+id/include1"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_alignParentBottom="true"
    layout="@layout/two_button_bar" />

I've read a few answers around and they all point to setting both the include> and merge> to wrap_content for height and width, but that is how I already had it, and it's still a no-go.

Any ideas?

daniel_c05
  • 11,438
  • 17
  • 60
  • 78

2 Answers2

2

<include /> is really just cut & paste and <merge /> means join the RelativeLayout. So you need to give these elements RelativeLayout rules, try adding:

android:layout_above="@+id/button_container"

To the divider View. And add:

android:layout_alignParentBottom="true"

To the LinearLayout.

Sam
  • 86,580
  • 20
  • 181
  • 179
  • Worked perfectly, thanks, I would assume I could set the properties in the include tag itself, I guess it doesn't work that way :P – daniel_c05 Apr 07 '13 at 23:15
  • [That assumption isn't wrong](http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/) necessarily, but I believe `` trumps `` in this instance. – Sam Apr 07 '13 at 23:32
0

You could give an id in the tag in your xml and then the layout in your RelativeLayout you want below it you can just use the layout_below="@id/-includedlayout-id

This will align the layout like you want it.

<include android:id="@+id/include1"
layout="-yourLayout-"/>

<RelativeLayout
...
android:layout_below="@id/include1>
Draken
  • 3,134
  • 13
  • 34
  • 54
Nairiya
  • 33
  • 1
  • 5