2017-08-10 83 views
0

在我的绘制文件夹CardView边界不会改变

cardeviewborder.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="@color/colorAccent"/> 
    <stroke android:width="3dip" android:color="#B1BCBE" /> 
    <corners android:radius="20dip"/> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape> 

在布局文件夹

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:background="@android:color/white" 
    android:layout_height="wrap_content" 
    android:padding="10dp"> 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:elevation="4dp" 
     android:layout_gravity="center" 
     android:background="@drawable/cardviewborder" 
     > 



     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/listitemtaskname" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="5dp" 
       android:textSize="25sp" 
       android:textStyle="bold" 
       tools:text="Hi" /> 


      <TextView 
       android:id="@+id/listitemdatedetails" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="5dp" 
       android:textSize="15sp" 
       tools:text="By" /> 


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

CardView边框没有change.What我做错了,我想cardview在相对布局之上提升,但即使在添加提升属性后也不会发生。请帮助 我希望我的carview看起来像这样与borde [R enter image description here

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/listitemtaskname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      tools:text="Hi" /> 

     <TextView 
      android:id="@+id/listitemdatedetails" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="5dp" 
      android:textSize="15sp" 
      tools:text="By" /> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

检查通过除去相对布局,cardview将提升。

0

您应该使用app:cardBackgroundColor改变CardView的研究背景,而不影响CardView的标高。

如果你使用这个属性,你会失去CardView的海拔:android:background

+0

我想chnage cardview的边框,并从RelativeLayout提升它。现在似乎没有cardview,因为cardview和relativelayout都显示为相同 – Cycle

+0

是的。如果您使用此属性,则会失去高度:'android:background' – Bob