2015-08-09 48 views
1

这是我试过的。但该按钮出现在卡的下方。有人可以告诉我怎样才能使卡上方的按钮可见。这表示回收商视图中的一行。如何在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

交换按钮和卡位置到这个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" 
    /> 
+0

谢谢。它的工作 –

+0

很好的答案...非常困难的问题永远:) –

相关问题