2016-09-05 6 views
5

मेरे Android डिवाइस 4.3 है और cardView का दौर कोने से काम नहीं करते:गोलाकार कोनों कार्ड देखें रीसाइक्लर व्यू में काम नहीं करते - एंड्रॉइड?

<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> 

और मैं मेरी कक्षा में bellow कोड लिखने, लेकिन अभी तक काम नहीं करते:

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

[कार्डव्यू कॉर्नर त्रिज्या] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/29342633/cardview-corner-radius) – TWL

+1

@ TWL.I इस लिंक को पढ़ते हैं। यह मेरी प्रतिक्रिया नहीं है। –

उत्तर

16

ऐसा लगता है कि एक CardView पर View.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" 

यहाँ पहली विशेषता के लिए प्रलेखन (जो दूसरे के लिए संदर्भ शामिल हैं) https://developer.android.com/reference/android/support/v7/widget/CardView.html#setPreventCornerOverlap(boolean)

इस चाल करना चाहिए है

संबंधित मुद्दे