2016-12-03 2 views
1

Je suis actuellement occupé avec une page de détails. Je me demandais maintenant comment je pourrais faire ressembler un cardview à celui que j'ai conçu. Je n'arrive pas à trouver sur google comment le faire. Je veux que la carte soit multicolore: 25% du haut devrait être blanc, et le 75 restant au bas devrait être rouge. Comment puis-je le faire? Je pensais à des drawables, mais je pense que ça aura l'air moche avec différents téléphones.Cardview avec plusieurs couleurs d'arrière-plan

je le veux ressembler à ceci:

enter image description here

Je possède ce Vignettes:

<android.support.v7.widget.CardView 
    android:id="@+id/view4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:layout_marginTop="24dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/material_grey_50" 
     android:orientation="vertical"> 

     <TextView 
      style="@style/TextViewAppearance.Body3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="16dp" 
      android:layout_marginTop="16dp" 
      android:text="Descriptie" 
      android:textColor="?attr/colorPrimaryDark" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="8dp" 
      android:layout_marginTop="8dp" 
      android:background="@color/material_grey_200" /> 

     <TextView 
      android:id="@+id/descriptionText" 
      style="@style/TextViewAppearance.Body2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="16dp" 
      android:layout_marginLeft="16dp" 
      android:layout_marginRight="16dp" 
      android:layout_marginTop="16dp" 
      android:textColor="@color/material_grey_600" /> 

    </LinearLayout> 

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

Répondre

-1

Vous pouvez le faire en ajoutant une disposition linéaire, définissez la largeur pour remplir parent et Définir c'est la couleur de fond.

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:background="@color/black" 
    android:layout_marginTop="5dp"> 

    <TextView 
     android:id="@+id/descriptionText" 
     style="@style/TextViewAppearance.Body2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:textColor="@color/material_grey_600" /> 
</LinearLayout> 
0

Essayez d'utiliser le poids et weightSum comme ceci:

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

    <TextView 
     style="@style/TextViewAppearance.Body3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="16dp" 
     android:text="Descriptie" 
     android:textColor="?attr/colorPrimaryDark" 
     android:background="@color/material_grey_50" 
     android:layout_weight="1" /> 

    <TextView 
     android:id="@+id/descriptionText" 
     style="@style/TextViewAppearance.Body2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:textColor="@color/material_grey_600" 
     android:layout_weight="3"/> 
    </LinearLayout>