如何在cardview上放置一半按钮,在父布局上放置一半按钮

时间:2015-08-09 11:47:37

标签: android button layout android-cardview

这就是我尝试过的。但按钮出现在卡片下方。有人可以告诉我如何在卡上方显示按钮。这表示回收者视图中的一行。

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

    <Button
        android:layout_width="50dp"
        android:layout_height="30dp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="10dp"
       />

    <android.support.v7.widget.CardView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pList"
        card_view:cardElevation="2sp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        card_view:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:layout_marginLeft="10dp"
            >
            </RelativeLayout>
        </android.support.v7.widget.CardView>
</RelativeLayout>

1 个答案:

答案 0 :(得分:2)

将按钮和卡位置交换到此xml布局文件中。您还应该为Button设置一个高程,例如4dp。

<android.support.v7.widget.CardView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/pList"
    card_view:cardElevation="2sp"
    android:layout_marginRight="16dp"
    android:layout_marginLeft="16dp"
    card_view:cardUseCompatPadding="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:layout_marginLeft="10dp"
        >
        </RelativeLayout>
    </android.support.v7.widget.CardView>`

    <Button
    android:layout_width="50dp"
    android:layout_height="30dp"
    android:layout_marginTop="20dp"
    android:layout_marginLeft="10dp"
    android:elevation="4dp"
   />
相关问题