2017-03-20 1 views
0

Ich habe ein Problem bezüglich der Füllung eines Teils einer Android-Karte mit einer Hintergrundfarbe.Setzen Sie Hintergrundfarbe auf Android-Karte Kanten zu

Wie Sie sehen können, füllt der blau gefüllte Bereich nicht die Kanten der Karte. Ich weiß nicht genau, wie das setzen, vielleicht wird mein Layout-Datei Ihnen helfen: , dass die Art und Weise ist die Karte sucht jetzt:

enter image description here

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/card_view" 
    android:layout_margin="5dp" 
    card_view:cardCornerRadius="12dp" 
    card_view:cardElevation="3dp" 
    card_view:contentPadding="4dp" 
    android:foreground="?selectableItemBackground" 
    android:clickable="true" > 


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

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="6dp"> 

      <ImageView 
       android:id="@+id/item_image" 
       android:layout_width="80dp" 
       android:layout_height="80dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:layout_marginRight="8dp" 

       card_view:srcCompat="@drawable/ic_face" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/item_title" 
       android:layout_toRightOf="@+id/item_image" 
       android:layout_alignParentTop="true" 
       android:textSize="30sp" 
       android:text="Temp Content" 
       /> 

      <TextView 
       android:id="@+id/item_subtitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/item_title" 
       android:layout_toRightOf="@+id/item_image" 
       android:text="3 Teilnehmer" /> 

     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:padding="6dp" 
      android:background="@color/colorPrimary"> 

      <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:orientation="vertical"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentStart="true" 
         android:layout_alignParentTop="true" 
         card_view:srcCompat="@android:drawable/ic_media_next" /> 

        <TextView 
         android:id="@+id/item_next_name" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:text="Test Name" /> 
       </LinearLayout> 
      </LinearLayout> 

      <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:orientation="vertical" 
       android:gravity="right"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 
        <TextView 
         android:id="@+id/item_next_date" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:text="20.03.2017" /> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentStart="true" 
         android:layout_alignParentTop="true" 
         card_view:srcCompat="@android:drawable/ic_media_next" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

    </LinearLayout> 

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

Wie kann ich die Hintergrundfarbe einstellen müssen befülle auch die Kanten der Karte? Vielen Dank!

+0

Mögliche Duplikat [Android CardView entfernen padding] (http://stackoverflow.com/questions/31299577/android-cardview- entfernen-padding) –

Antwort

1

Ich hatte Probleme mit der Lösung, in this answer vorgeschlagen, insbesondere die akzeptierte Antwort dies empfiehlt die Anwendung, aber es hilft mir nicht:

card_view:cardPreventCornerOverlap="false" 

Was ich mit, am Ende wurde card_view:contentPadding von CardView zu entfernen und die Anwendung notwendiges Auffüllen zu untergeordneten Ansichten.

In Ihrem Fall wäre dies das Ergebnis:

enter image description here

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dp" 
    android:clickable="true" 
    android:foreground="?selectableItemBackground" 
    card_view:cardCornerRadius="12dp" 
    card_view:cardElevation="3dp"> 

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

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="10dp"> 

      <ImageView 
       android:id="@+id/item_image" 
       android:layout_width="80dp" 
       android:layout_height="80dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" 
       android:layout_marginRight="8dp" 

       card_view:srcCompat="@android:drawable/alert_dark_frame"/> 

      <TextView 
       android:id="@+id/item_title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/item_image" 
       android:text="Temp Content" 
       android:textSize="30sp" 
      /> 

      <TextView 
       android:id="@+id/item_subtitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/item_title" 
       android:layout_toRightOf="@+id/item_image" 
       android:text="3 Teilnehmer"/> 

     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" 
      android:orientation="horizontal" 
      android:padding="6dp"> 

      <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:orientation="vertical"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentStart="true" 
         android:layout_alignParentTop="true" 
         card_view:srcCompat="@android:drawable/ic_media_next"/> 

        <TextView 
         android:id="@+id/item_next_name" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:text="Test Name"/> 
       </LinearLayout> 
      </LinearLayout> 

      <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" 
          android:layout_weight="1" 
          android:gravity="right" 
          android:orientation="vertical"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 
        <TextView 
         android:id="@+id/item_next_date" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:text="20.03.2017"/> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentStart="true" 
         android:layout_alignParentTop="true" 
         card_view:srcCompat="@android:drawable/ic_media_next"/> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

    </LinearLayout> 

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

Wow! Sieht super aus! Danke für die Antwort! Könntest du bitte auch deine XML-Datei posten, damit ich das überprüfen kann? Grüße – romaneso

+0

@romaneso, aktualisiert. – azizbekian

+0

Das ist unglaublich, wie einfach das war. Kleine Dinge können manchmal sehr schwierig sein. – romaneso

Verwandte Themen