1


У меня есть следующий вид, созданный с помощью CardView.
Добавление зависимости compile 'com.android.support:cardview-v7:23.0.+' в зависимости от градимента

Ниже приведен файл xml для него.Вид карты не подходит в 5.1.1 Tablet и 5.0.2 Мобильное устройство

<android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/cardViewEmp" 
       android:layout_height="wrap_content" 
       android:layout_width="0dp" 
       android:layout_weight="0.50" 
       card_view:cardCornerRadius="20dp" 
       card_view:cardElevation="10dp" 
       android:padding="@dimen/margin_10" 
       > 
       <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        > 
       <ImageView 
        android:id="@+id/employeeIcon" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="@dimen/margin_5" 
        android:src="@drawable/employeeicon" 
        android:layout_centerHorizontal="true" 
        /> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Employee" 
        android:layout_centerHorizontal="true" 
        android:layout_below="@+id/employeeIcon" 
        android:textSize="@dimen/textSizeNormal" 
        /> 
       </RelativeLayout> 
      </android.support.v7.widget.CardView> 


      <android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/cardViewVehicle" 
       android:layout_height="wrap_content" 
       android:layout_width="0dp" 
       android:layout_weight="0.50" 
       card_view:cardCornerRadius="20dp" 
       card_view:cardElevation="10dp" 
       android:padding="@dimen/margin_10" 
       > 
       <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        > 
        <ImageView 
         android:id="@+id/vehicleIconLive" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:paddingTop="@dimen/margin_5" 
         android:src="@drawable/vehicleicon" 
         android:layout_centerHorizontal="true" 
         /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Vehicle" 
         android:layout_centerHorizontal="true" 
         android:layout_below="@+id/vehicleIconLive" 
         android:textSize="@dimen/textSizeNormal" 
         /> 
       </RelativeLayout> 
       </android.support.v7.widget.CardView> 

Теперь высота и внешний вид для вида в 4.4.4 мобильных устройствах показаны ниже, которые выглядят хорошо!
enter image description here

Но то же самое выглядит очень странно в 5.1.1 планшетах Nexus и 5.0.2 Мобильный, как показано ниже.
enter image description here

Я добавил высоту и радиус угла этой

card_view:cardCornerRadius="20dp" 
card_view:cardElevation="10dp" 
  • Любой может ясно видеть, радиус закругления угла выглядит странно без соответствующей высоте.
  • В чем может быть проблема.
  • Что можно сделать, чтобы сделать правильный вид и CardView

Edit 1:
Пробовал с com.android.support:cardview-v7:23.1.1, но выход снова был таким же.

+0

вызов 'компилировать«com.android.support: cardview-v7: 23.1.1'' –

+1

@IntelliJAmiya Я попробовал то же самое. Не работает в 5.1.1 планшет Nexus !!! – Stallion

ответ

0

Наконец-то я понял вопрос. Это произошло из-за внешнего LinearLayout, который я написал, чтобы сделать значки в центре экрана, который имел высоту как wrap_content. Я избегал LinearLayout и через следующий код я сделал вид карты с правильными кривыми высоты и посередине.

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/mainRL" 
     > 
<android.support.v4.widget.Space 
       android:layout_width="@dimen/margin_10" 
       android:layout_height="1dp" 
       android:layout_centerInParent="true" 
       android:layout_centerVertical="true" 
       android:id="@+id/spaceCenter" 
       /> 
<!-- Employee icon --> 

      <android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/cardViewEmp" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       card_view:cardCornerRadius="20dp" 
       card_view:cardElevation="10dp" 
       android:layout_toLeftOf="@+id/spaceCenter" 
       android:layout_centerInParent="true" 
       > 
       <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        > 
       <ImageView 
        android:id="@+id/employeeIcon" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="@dimen/margin_5" 
        android:src="@drawable/employeeicon" 
        android:layout_centerHorizontal="true" 
        /> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text=" Employee " 
        android:layout_centerHorizontal="true" 
        android:layout_below="@+id/employeeIcon" 
        android:textSize="@dimen/textSizeNormal" 
        /> 
       </RelativeLayout> 
      </android.support.v7.widget.CardView> 

      <!-- Vehicle icon --> 

      <android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/cardViewVehicle" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       card_view:cardCornerRadius="20dp" 
       card_view:cardElevation="10dp" 
       android:layout_toRightOf="@+id/spaceCenter" 
       android:layout_centerInParent="true" 
       > 
       <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        > 
        <ImageView 
         android:id="@+id/vehicleIconLive" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:paddingTop="@dimen/margin_5" 
         android:src="@drawable/vehicleicon" 
         android:layout_centerHorizontal="true" 
         /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text=" Vehicle  " 
         android:layout_centerHorizontal="true" 
         android:layout_below="@+id/vehicleIconLive" 
         android:textSize="@dimen/textSizeNormal" 
         /> 
       </RelativeLayout> 
       </android.support.v7.widget.CardView> 
</RelativeLayout> 
2

Попробуйте удалить: android: padding Атрибут из вида карты.

из документации:

Поскольку прокладка используется для компенсации содержания для теней, вы не можете установить отступов на CardView. Вместо этого вы можете использовать атрибуты атрибутов контента в XML или setContentPadding (int, int, int, int) в коде, чтобы установить прокладку между краями Карты и дочерними элементами CardView.

Кроме этого:

Обратите внимание, что, если указать точные размеры для CardView, потому что теней, его площадь содержание будет отличаться между платформами до L и после L. Используя api версии конкретных значений ресурсов, вы можете избежать этих изменений. В качестве альтернативы, если вы хотите, чтобы CardView до , добавьте внутреннюю прокладку на платформах L и после этого, вы можете установить setUseCompatPadding (boolean) в true.

0

Чтобы сделать его как совместимый выше или ниже API 21, вам необходимо указать приложение: cardUseCompatPadding = «истина» в вашем CardView поддержки.

кредит ShinChven CardView elevation not working on Android 5.1.1