2017-03-29 1 views
1

j'essaie d'ajouter arrière-plan personnalisé dans mes CardView.This est ma sourceVignettes arrière-plan personnalisé

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/item_container" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#ff00" 
android:orientation="vertical"> 


<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="12dp" 
    card_view:cardElevation="12dp" 
    card_view:cardPreventCornerOverlap="false" 
    card_view:contentPadding="0dp" 
    android:layout_margin="16dp" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:orientation="vertical"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:background="#cccccc"> 
     </RelativeLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

And this is a result

Comme vous pouvez le voir dans Vignettes j'ai la couleur de fond de LinearLayout et RelativieLayout.RelativeLayout est # cccccc, mais cornerradius et elevetion ne fonctionnent pas avec la couleur d'arrière-plan personnalisée. (S'il vous plaît voir ma photo) Comment puis-je résoudre mon problème?

Répondre

1

Votre disposition linéaire intérieur est Vignettes qui se chevauchent coins supérieurs de votre en raison de Vignettes fixer la hauteur donnée à la disposition linéaire. Lorsque vous donnez de la hauteur à CardView et que vous créez une disposition linéaire match_parent, et que vous donnez contentPadding dans CardView, les coins sont visibles.

Voici le code et la capture d'écran.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/item_container" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#ff00" 
android:orientation="vertical"> 


<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="80dp" 
    card_view:cardCornerRadius="12dp" 
    card_view:cardElevation="12dp" 
    card_view:cardPreventCornerOverlap="true" 
    card_view:contentPadding="2dp" 
    android:layout_margin="16dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:background="#cccccc"> 
     </RelativeLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
</LinearLayout> 

Screenshot

Image

+0

Est-il possible de changer une couleur d'arrière-plan sans marges? Je veux dire la marge gauche et droite? @Vivek Mishra – BekaKK

+0

Je pense que l'utilisation d'une image comme celle-ci comme arrière-plan de votre cardview sera meilleure. –

+0

Instance de couleur ccccc? @Vivek Mishra – BekaKK