2017-02-23 11 views
1

У меня есть CardView с некоторым радиусом угла, внутри которого расположены три относительных макета. Когда я устанавливаю фон макета, вершина которого выровнена с вершиной CardView, радиус угла теряется.Персистентный угловой радиус CardView при настройке фона макета внутри этого CardView

enter image description here

Как сохранить радиус угла?

Код:

<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="false" 
    android:layout_centerHorizontal="false" 
    android:layout_centerInParent="true" 
    app:cardCornerRadius="10dp" 
    android:clipToPadding="true" 
    app:cardPreventCornerOverlap="false"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/rlBase" 
     android:clipChildren="true" 
     android:clipToPadding="true" 
     android:animateLayoutChanges="false"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:id="@+id/rlOverallPerformance" 
      android:background="@color/lightBlue" 
      android:clipToPadding="false" 
      android:clipChildren="false"> 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:id="@+id/rlRealizedValue" 
      android:layout_below="@+id/rlOverallPerformance"> 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="30dp" 
      android:id="@+id/rlUnrealizedValue" 
      android:layout_below="@+id/rlRealizedValue" 
      android:elevation="1dp"> 

     </RelativeLayout> 

    </RelativeLayout> 

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

набор Маржа ДО 10dp каждого относительного расположения ребенка –

+0

это вы ее решили? – dharmx

+1

@dharmx для меня он отлично работал на устройстве. Только предварительный просмотр был неправильным –

ответ

1

Окружите вашего CardView с другими ViewGroup элементом, как FrameLayout, LinearLayout или RelativeLayout. Даже я столкнулся с такой же проблемой, и тогда это сработало. Я его где-то читал.

Файл: listitem_screen.xml

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

    <include layout="@layout/listitem_screen_base" /> 
</RelativeLayout> 

Я использую <include> тег, как я использую тот же макет в разных местах.

Файл: listitem_screen_base.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/root" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:cardBackgroundColor="@color/windowBackground" 
    app:cardCornerRadius="@dimen/rect_corner_radius" 
    app:cardElevation="@dimen/cardview_default_elevation" 
    app:cardPreventCornerOverlap="true" 
    app:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:id="@+id/ll_base" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <com.company.app.custom.CustomImageView 
       android:id="@+id/img_poster" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true" 
       android:scaleType="fitXY" 
       android:src="@color/black3" 
       app:calculation_type="height" 
       app:ratio_height="@integer/inspire_img_height_ratio" 
       app:ratio_width="@integer/inspire_img_width_ratio" 
       app:riv_corner_radius_top_left="@dimen/rect_corner_radius" 
       app:riv_corner_radius_top_right="@dimen/rect_corner_radius" /> 

      <com.company.app.custom.FontTextView 
       android:id="@+id/lbl_new" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_marginBottom="20dp" 
       android:background="@drawable/shape_rect_round_border_right_yellow_fill" 
       android:paddingBottom="2dp" 
       android:paddingEnd="6dp" 
       android:paddingLeft="6dp" 
       android:paddingRight="6dp" 
       android:paddingStart="6dp" 
       android:paddingTop="2dp" 
       android:text="@string/s_new" 
       android:textColor="?android:attr/textColorPrimary" 
       android:textSize="9.72sp" 
       app:customFont="@string/font_circular_book" /> 

     </FrameLayout> 

     <com.company.app.custom.FontTextView 
      android:id="@+id/lbl_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="start|center_vertical" 
      android:layout_marginBottom="13dp" 
      android:layout_marginEnd="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginStart="10dp" 
      android:layout_marginTop="15dp" 
      android:ellipsize="end" 
      android:gravity="center_vertical|start" 
      android:maxLines="2" 
      android:minHeight="38dp" 
      android:textAlignment="viewStart" 
      android:textColor="?android:textColorPrimaryInverse" 
      android:textSize="16sp" 
      app:customFont="@string/font_circular_book" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="13dp" 
      android:layout_marginEnd="10dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginStart="10dp"> 

      <com.company.app.custom.FontTextView 
       android:id="@+id/lbl_time" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:textColor="?android:attr/textColorTertiary" 
       android:textSize="12sp" 
       app:customFont="@string/font_avenir_medium" /> 

      <ImageView 
       android:id="@+id/dot1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginEnd="14dp" 
       android:layout_marginLeft="14dp" 
       android:layout_marginRight="14dp" 
       android:layout_marginStart="14dp" 
       android:layout_toEndOf="@+id/lbl_time" 
       android:layout_toRightOf="@+id/lbl_time" 
       android:scaleType="centerInside" 
       android:src="@drawable/dot" /> 

      <com.company.app.custom.FontTextView 
       android:id="@+id/lbl_views" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toEndOf="@+id/dot1" 
       android:layout_toRightOf="@+id/dot1" 
       android:textColor="?android:attr/textColorTertiary" 
       android:textSize="12sp" 
       app:customFont="@string/font_avenir_medium" /> 

      <ImageView 
       android:id="@+id/dot2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginEnd="14dp" 
       android:layout_marginLeft="14dp" 
       android:layout_marginRight="14dp" 
       android:layout_marginStart="14dp" 
       android:layout_toEndOf="@+id/lbl_views" 
       android:layout_toRightOf="@+id/lbl_views" 
       android:scaleType="centerInside" 
       android:src="@drawable/dot" /> 

      <com.company.app.custom.FontTextView 
       android:id="@+id/lbl_tag" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_toEndOf="@+id/dot2" 
       android:layout_toRightOf="@+id/dot2" 
       android:textColor="@color/colorAccent" 
       android:textSize="12sp" 
       app:customFont="@string/font_avenir_medium" /> 

     </RelativeLayout> 

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

My CardView уже находится в относительном расположении, о котором я не упоминал в фрагменте кода, который я опубликовал. Я не понимаю, как это решит проблему. –

+0

change 'app: cardPreventCornerOverlap =" true "' from' app: cardPreventCornerOverlap = "false" ' –