2017-11-01 1 views
1

Es gibt viele Fragen über Cardview Elevation hier und ich versuchte alle Lösung, um das Problem zu lösen, aber es funktioniert immer noch nicht. Ich habe card_view: cardUseCompatPadding = "true" in cardview hinzugefügt und ich habe auch versucht, die Hardwarebeschleunigung im Android-Manifest auf true zu setzen. Ich lese auch, dass wenn ich Padding in Cardview verwende, könnte es die Schatten für die Kartenansicht ausschneiden. Kann mir jemand sagen, was ich falsch mache? Ich kann die Schatten im Android-Studio sehen, aber nicht auf dem Emulator oder realen Gerät.Karte Ansicht nicht angezeigt

<?xml version="1.0" encoding="utf-8"?> 

     <android.support.v7.widget.CardView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 

      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="20dp" 
      card_view:cardBackgroundColor="@android:color/white" 
      card_view:cardCornerRadius="4dp" 
      card_view:cardElevation="6dp" 
      android:id="@+id/cardView" 
      card_view:cardUseCompatPadding="true" 
      > 

      <android.support.constraint.ConstraintLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="@dimen/horizontal_spacing"> 

       <ImageView 
        android:id="@+id/imageView" 
        android:layout_width="36dp" 
        android:layout_height="36dp" 
        android:layout_gravity="end" 
        app:layout_constraintEnd_toEndOf="parent" 
        app:layout_constraintTop_toTopOf="parent" 
        app:srcCompat="@drawable/aboutpallogo"/> 

       <TextView 
        android:id="@+id/textView" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_marginEnd="16dp" 
        android:textSize="14dp" 
        android:textAppearance="@style/TextAppearance.AppCompat.Headline" 
        android:textColor="#171652" 
        android:textDirection="rtl" 
        app:layout_constraintBottom_toBottomOf="@+id/imageView" 
        app:layout_constraintEnd_toStartOf="@+id/imageView" 
        app:layout_constraintStart_toStartOf="parent" 
        tools:text="Header"/> 

       <TextView 
        android:id="@+id/textView2" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="8dp" 
        android:text="TextView" 
        android:textDirection="rtl" 
        android:textColor="#4cbea9" 
        app:layout_constraintEnd_toEndOf="@+id/textView" 
        app:layout_constraintStart_toStartOf="parent" 
        app:layout_constraintTop_toBottomOf="@+id/textView"/> 

       <View 
        android:id="@+id/divider" 
        android:layout_width="0dp" 
        android:layout_height="1dp" 
        android:layout_marginTop="8dp" 
        android:background="@drawable/divider" 
        app:layout_constraintEnd_toEndOf="@+id/textView2" 
        app:layout_constraintStart_toStartOf="parent" 
        app:layout_constraintTop_toBottomOf="@+id/textView2"/> 

       <com.mediamer.apps.pal_library.helpers.ExpandableTextView 
        android:id="@+id/expandableTextView" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="8dp" 
        android:layout_marginEnd="16dp" 
        android:layout_marginTop="24dp" 
        app:expanded="true" 
        app:layout_constraintBottom_toBottomOf="parent" 
        app:layout_constraintEnd_toEndOf="@+id/textView2" 
        app:layout_constraintEnd_toStartOf="@+id/imageView" 
        app:layout_constraintStart_toStartOf="parent" 
        app:layout_constraintTop_toBottomOf="@+id/divider" 
        /> 
      </android.support.constraint.ConstraintLayout> 
     </android.support.v7.widget.CardView> 

Antwort

0

Versuchen

android:elevation="6dp" 

in

<android.support.v7.widget.CardView 

Abschnitt setzen. Auch die Information, wie Sie diese Cardview verwenden, kann nützlich sein.

+0

Ich habe versucht, aber nicht funktioniert. – abdo

+0

Ich verwende Cardview in Gridview. Ich erstellte auch eine andere Aktivität und versuchte, die Cardview zu testen, um zu sehen, ob die Gridview der Grund ist, warum der Schatten nicht angezeigt wird, aber es hat nicht so gut funktioniert – abdo

0

Verwenden Sie diesen Code statt:

<android.support.v7.widget.CardView 
      android:id="@+id/report_details_card" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:cardBackgroundColor="@color/colorWhite" 
      app:cardCornerRadius="@dimen/cardview_default_radius" 
      app:cardElevation="@dimen/cardview_default_elevation" 
      app:cardUseCompatPadding="true"> 
</android.support.v7.widget.CardView> 

Sie haben gerade

card_view:cardCornerRadius="4dp" 
    card_view:cardElevation="6dp" 
    card_view:cardUseCompatPadding="true" 

mit

app:cardUseCompatPadding="true" 
    app:cardCornerRadius="4dp" 
    app:cardElevation="6dp" 

Jetzt ersetzen Sie sind gut zu gehen. Happy coding :)