我想在布局下面放置一个按钮来自我包含的另一个xml文件,但它只是漂浮在它上面。我尝试使用RelativeLayout和LinearLayout封装它们,但它仍然没有用,所以我不确定我做错了什么。代码:
<?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>
答案 0 :(得分:2)
试试这个
<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>
编辑完整代码
<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>
答案 1 :(得分:1)
尝试在按钮标记中添加android:layout_marginTop="16dp"
android:layout_gravity="bottom"
。你可以改变dp。