maregor
maregor

Reputation: 797

Placing button below include layout

I want to place a button below a layout from another xml file that I included, but it just floats above it. I tried enclosing them using RelativeLayout and LinearLayout but it still didn't work, so I'm not sure what I'm doing wrong. Code:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.CardView
    android:id="@+id/card_detail"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_gravity="top|center_horizontal"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="false"
    android:layout_margin="@dimen/activity_horizontal_margin"
    card_view:cardCornerRadius="5dp"
    card_view:cardBackgroundColor="@color/accent">

    <include layout="@layout/common_item_layout" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Delete"
        android:onClick="removeItem"
        android:id="@+id/delete_button" />

</android.support.v7.widget.CardView>

Upvotes: 0

Views: 714

Answers (2)

Amit Kumar
Amit Kumar

Reputation: 1458

Try to add android:layout_marginTop="16dp" android:layout_gravity="bottom" in button tag. You can change the dp.

Upvotes: 2

Bhargav Thanki
Bhargav Thanki

Reputation: 4954

Try this

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent">

        <include 
            android:id="@+id/layout"
            layout="@layout/common_item_layout" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delete"
            android:onClick="removeItem"
            android:id="@+id/delete_button" 
            android:layout_below="@+id/layout"
            android:layout_marginTop="10dp"/>

    </RelativeLayout>

EDIT Complete code

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.v7.widget.CardView 
    android:id="@+id/card_detail"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_gravity="top|center_horizontal"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="false"
    android:layout_margin="@dimen/activity_horizontal_margin"
    card_view:cardCornerRadius="5dp"
    card_view:cardBackgroundColor="@color/accent">

    <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent">
        <include 
            android:id="@+id/layout"
            layout="@layout/common_item_layout" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delete"
            android:onClick="removeItem"
            android:id="@+id/delete_button" 
            android:layout_below="@+id/layout"/>

    </RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>

Upvotes: 2

Related Questions