2015-12-24 12 views
8

Ich möchte nur die Spitze eines cardview Ecke.Runde nur obere Ecke von cardview

Ich verwendete unter Eigentum und es ist rund um die Ecke.

Ich möchte eine Überlappung aller Karten zeigen

card_view:cardCornerRadius="4dp" 

hier ist mein Layout

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    card_view:cardCornerRadius="4dp" 
    card_view:cardPreventCornerOverlap="false" 
    > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:id="@+id/re1"> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="match_parent" 
      android:layout_height="20dp" 
      android:background="@color/colorAccent" 
      android:text="contact det" 
      android:gravity="center_vertical" 
      android:textColor="@android:color/white" 
      android:textSize="14dp"/> 

     <TextView 
      android:id="@+id/txtName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Name" 
      android:gravity="center_vertical" 
      android:textSize="10dp" 
      android:layout_below="@id/title" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="5dp"/> 

     <TextView 
      android:id="@+id/txtSurname" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Surname" 
      android:gravity="center_vertical" 
      android:textSize="10dp" 
      android:layout_below="@id/txtName" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="5dp" 
      /> 

     <TextView 
      android:id="@+id/txtEmail" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Email" 
      android:textSize="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="150dp" 
      android:layout_alignBaseline="@id/txtName"/> 

     <TextView 
      android:id="@+id/txtAdd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Address" 
      android:textSize="10dp" 
      android:layout_alignLeft="@id/txtEmail" 
      android:layout_alignBaseline="@id/txtSurname"/> 

    </RelativeLayout> 


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

Antwort

0

Gemäß der Frage, ich gehe davon aus, dass Sie Eckradius Eigenschaft nur oben anwenden möchten der Karte. Sie können diesen Effekt erhalten, indem Sie zwei CardView verwenden. Platzieren Sie einen CardView innerhalb eines anderen CardView und entfernen Sie die äußere Eckenradiuseigenschaft CardView. Tragen Sie auch einen transparenten Hintergrund auf Ihre äußere CardView Ihre innere CardView wird einen cornerRadius Wert von 4dp haben. Dann wenden Sie einen marginTop auf Ihre innere CardView, so dass sein unterer Teil durch die äußere CardView verdeckt wird. Auf diese Weise wird der untere Eckenradius Ihres inneren CardView ausgeblendet.

Sie müssen Ihren XML-Inhalt in Ihrem Inneren CardView setzen. Äußere CardView dient nur zum Verstecken der unteren abgerundeten Ecken des inneren CardView. Ihr XML-Layout wird wie folgt aussehen:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view_outer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    card_view:cardBackgroundColor="@android:color/transparent" 
    card_view:cardCornerRadius="0dp" 
    card_view:cardElevation="4dp" > 

<android.support.v7.widget.CardView 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="3dp" 
    card_view:cardElevation="0dp" 
    card_view:cardCornerRadius="4dp" 
    > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:id="@+id/re1"> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="match_parent" 
      android:layout_height="20dp" 
      android:background="@color/colorAccent" 
      android:text="contact det" 
      android:gravity="center_vertical" 
      android:textColor="@android:color/white" 
      android:textSize="14dp"/> 

     <TextView 
      android:id="@+id/txtName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Name" 
      android:gravity="center_vertical" 
      android:textSize="10dp" 
      android:layout_below="@id/title" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="5dp"/> 

     <TextView 
      android:id="@+id/txtSurname" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Surname" 
      android:gravity="center_vertical" 
      android:textSize="10dp" 
      android:layout_below="@id/txtName" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="5dp" 
      /> 

     <TextView 
      android:id="@+id/txtEmail" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Email" 
      android:textSize="10dp" 
      android:layout_marginTop="10dp" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="150dp" 
      android:layout_alignBaseline="@id/txtName"/> 

     <TextView 
      android:id="@+id/txtAdd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Address" 
      android:textSize="10dp" 
      android:layout_alignLeft="@id/txtEmail" 
      android:layout_alignBaseline="@id/txtSurname"/> 

    </RelativeLayout> 


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

I Referenz von dieser Frage SO genommen habe: Question. Ich hoffe, es löst Ihr Problem.

+0

Immer noch gibt es Ecken an der Unterseite ... –

+0

Kopieren Sie genau den gleichen Code, den ich in Antwort geschrieben habe? – brainbreaker

7

Wir haben die Margin der Karte Ansicht in negativer value.Margin sollte denselben Wert wie Kartenradius festlegen. Zum Beispiel

<FrameLayout 
     android:id="@+id/rootview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_view" 
     android:layout_marginBottom="-3dp" 
     project:cardCornerRadius="3dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!--The child view inside the cardview should have extra padding,so that negative margin will not affect the bottom padding of its child.Here normally we have 16dp bottom padding for child + margin bottom of the parent is 3dp=19dp comes.--> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingBottom="19dp"/> 

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

Es ist für me.but arbeitet ich im Zweifel bin, ob es die richtige Art und Weise der doing.Any Vorschläge ist willkommen.

+0

einfache native Lösung. funktioniert für mich – Bolein95

+0

dies funktioniert nur, wenn die Kartenansicht am unteren Rand des Bildschirms ist – tymbark

Verwandte Themen