2016-09-05 3 views
5

내 안드로이드 장치가 4.3하고 cardView의 둥근 모서리를 작동하지 않습니다둥근 모서리 cardView는 RecyclerView에서 작동하지 않습니다 - 안드로이드?

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/CardStart" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:scaleType="centerCrop" 
    app:cardUseCompatPadding="true" 
    card_view:cardBackgroundColor="@color/BlackTrans" 
    card_view:cardCornerRadius="5dp" 
    card_view:cardElevation="0dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

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

      <TextView 
       android:id="@+id/txtTitle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/txtDescription" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

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

      <ImageButton 
       android:id="@+id/imgbIcon" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:src="@drawable/ic_serch" /> 
     </LinearLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 

그리고 나는 내 수업에 울부 짖는 코드를 작성하지만, 아직 작동하지 않습니다

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) 
{ 
    holder.CardStart.setCardElevation(0); 
    holder.CardStart.setBackgroundColor(ContextCompat.getColor(context,R.color.BlackTrans)); 
    holder.CardStart.setRadius(5); 
    holder.CardStart.setUseCompatPadding(true); 
} 
+0

[CardView Corner Radius] (http://stackoverflow.com/questions/29342633/cardview-corner-radius) – TWL

+1

@ TWL의 가능한 복제본입니다.이 링크를 읽습니다. 그건 내 대답이 아니야. –

답변

16

그것은 밝혀 (두 번째에 대한 참조를 포함) 최초의 속성에 대한 설명서 https://developer.android.com/reference/android/support/v7/widget/CardView.html#setPreventCornerOverlap(boolean)

이 트릭을해야된다는 CardViewView.setBackgroundColor(int)를 호출 둥근 모서리를 제거합니다.

카드의 배경색을 변경하고 모서리를 유지하려면 대신 CardView.setCardBackgroundColor(int)으로 전화해야합니다.

이 게시물의 특정 방문자의 경우 일 수 있습니다.


, 내가 실수로 제거에서 모서리를 보호하기 위해 다음과 같은 방법을 추가 제안 CardView의 서브 클래스 :이었고, 나는 원주민 반응에 대한 사용자 정의보기 구현에 노력하고 특히

/** 
* Override prevents {@link View#setBackgroundColor(int)} being called, 
* which removes the rounded corners. 
*/ 
@Override 
public void setBackgroundColor(@ColorInt int backgroundColor) { 
    setCardBackgroundColor(backgroundColor); 
} 

과 반작용 자동으로보기에 배경색을 적용합니다. 이 오버라이드는이 문제를 해결했습니다. 이는 다른 개발자가 기본보기의 세부 사항을 알 필요가 없음을 의미합니다.

2

카드보기 여기

card_view:cardPreventCornerOverlap="false" 
card_view:cardUseCompatPadding="true"