14

Widziałem te CardViews (nie jestem pewien, czy są one nawet CardViews) z dzielnikami używanymi w wielu aplikacjach, więc domyślam się, że istnieje prosty sposób ich tworzenia. Chciałem zapytać, jak to dokładnie wygląda? czy to nawet CardViews?Cardview z dzielnikami w nim

Nie mogłem dowiedzieć się więcej o nich, ponieważ nie znałem dokładnie nazwy View, więc jeśli ktoś mógłby skierować mnie do przykładu z kodem, byłbym wdzięczny.

przykład zdjęcia: enter image description here

+0

myślę, że to z koniecznością ListItems tła i rozdzielacz parametry w liście. – Meenaxi

Odpowiedz

17

Można użyć tego kodu może pomóc

<android.support.v7.widget.CardView 
     android:id="@+id/cardview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/margin_large" 
     android:layout_marginRight="@dimen/margin_large" 
     android:elevation="100dp" 
     card_view:cardBackgroundColor="@android:color/white" 
     card_view:cardCornerRadius="8dp"> 

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

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:gravity="center_vertical" 
       android:paddingLeft="25dp"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Conversations" /> 
      </LinearLayout> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="2dp" 
       android:background="@android:color/darker_gray" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:paddingLeft="30dp" 
       android:paddingTop="20dp" 
       android:paddingBottom="10dp"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="game" /> 
        ... 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.CardView> 
+0

proszę również odpowiedzieć na to: http://stackoverflow.com/questions/36393540/no- shadow-elevation-underneath-second-card-if-there-are-two-card-in-the-layout –

+0

Proste, ale ładne –

9

Pokazany zrzut ekranu pokazuje normalne CardView z widokiem jak rozdzielacz pomiędzy. Brak DividerView lub coś podobnego, jeśli szukasz czegoś takiego. Po prostu użyj prostej View z wysokością i tłem.

Mam coś podobnego w mojej bibliotece. Używam tego, aby utworzyć dzielnik:

<View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@color/stroke"/> 

card_library.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:paddingBottom="8dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:gravity="center_vertical" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/libraryname" 
      style="@style/CardTitle" 
      android:fontFamily="sans-serif-condensed" 
      android:textStyle="normal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:maxLines="1"/> 

     <TextView 
      android:id="@+id/libraryversion" 
      style="@style/CardTitle" 
      android:fontFamily="sans-serif-condensed" 
      android:textStyle="normal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="4dp" 
      android:layout_marginTop="4dp" 
      android:gravity="left|bottom" 
      android:maxLines="1" 
      android:textSize="12sp"/> 

     <TextView 
      android:id="@+id/librarycreator" 
      style="@style/CardTitle" 
      android:fontFamily="sans-serif-condensed" 
      android:textStyle="normal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="2dp" 
      android:gravity="right" 
      android:maxLines="2" 
      android:textSize="14sp"/> 
    </LinearLayout> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_marginTop="4dp" 
     android:background="@color/stroke"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:padding="4dp"> 

     <TextView 
      android:id="@+id/description" 
      style="@style/CardText" 
      android:fontFamily="sans-serif-condensed" 
      android:textStyle="normal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:maxLines="20"> 
     </TextView> 
    </LinearLayout> 

</LinearLayout> 

Będzie wtedy wyglądać następująco:

Divider

+0

proszę odpowiedz również: http://stackoverflow.com/questions/36393540/no- shadow-elevation-underneath-second-card-if-there-are- two-card-in-the-layout –

+0

jaki kolor używasz ? – Caipivara

1

Zestaw aplikacji: cardElevation = "0DP", a następnie użyć View - patrz niżej

<android.support.v7.widget.CardView 
android:id="@+id/cv" 
xmlns:android="http://schemas.android.com/apk/res/android" 
app:cardElevation="0dp" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<!-- Insert UI elements --> 

    <View 
     android:layout_width="fill_parent" 
     android:background="@android:color/darker_gray" 
     android:layout_height="2dp"/> 

</android.support.v7.widget.CardView> 
Powiązane problemy