2012-02-16 12 views
15

बनाम है वहाँ किसी भी मैं android:background"@color/transparent" लेकिन इसकी कुछ अन्य विभिन्न पृष्ठभूमि रंग है कि मैं प्रयोग किया जाता दिखा सेट मेरी लेआउट में बनाम पारदर्शी (# 00000000)किसी भी diff @null # 00000000

@null के बीच का अंतर है।

जब मैंने अपना काम ठीक कर दिया।

मैं प्रोग्राम के माध्यम से @null सेट करना चाहता हूं।

कैसे करें?

+0

अपने color.xml में गलती हो या कोशिश कर सकते हैं '@Android: रंग/transparent'। – MKJParekh

+0

@ सोनी "00000000" और एंड्रॉइड से अलग है: रंग। दोनों एक ही सही हैं। –

+0

बस सेटबैकग्राउंड कॉलर() के साथ उलझन में सभी के लिए धन्यवाद। –

उत्तर

12

@null सभी में कोई पृष्ठभूमि का मतलब है (View.getBackground() रिटर्न नल)

#00000000 का अर्थ है कि आपको पृष्ठभूमि के रूप में एक रंगीन निकासी मिली है जिसमें पूर्ण पारदर्शी रंग है।

मैंने कोड को नहीं देखा, लेकिन मुझे लगता है कि रंगीन परीक्षण पूरी तरह पारदर्शी है और इस मामले में इसे आकर्षित नहीं करता है। अन्यथा आपके पास कुछ ड्राइंग ओवरहेड होगा, जिससे @null तेज विकल्प बन जाएगा। दोनों को समान दिखना चाहिए, इसलिए सुनिश्चित नहीं है कि यह आपकी अंतर्निहित आईएसई है।

कोड में @null के समतुल्य सेट करने के लिए, View.setBackgroundDrawable(null) का उपयोग करें।

2

पृष्ठभूमि में 0 सेट करें।

view.setBackgroundColor(0); 
8

हाँ, वहां है।

  • @null का मतलब कोई पृष्ठभूमि नहीं है।
  • #00000000 का मतलब है एक पारदर्शी पृष्ठभूमि जोड़ें।

यदि आपके पास पृष्ठभूमि नहीं है तो इसे @null बेहतर प्रदर्शन करना चाहिए। कोड से @null उपयोग करने के लिए आप क्या कर रही कोशिश कर सकते हैं:

widget.setBackgroundDrawable(null); 
1

मैं कहूंगा, ज्यादातर परिस्थितियों में @android पर @null पृष्ठभूमि पसंद करते हैं: रंग/पारदर्शी।

कोड में, सेटबैकग्राउंड (शून्य) का उपयोग करें जो एक बहिष्कृत विधि सेट बैकग्राउंड ड्रायबल();

यदि आप View.setBackgroundDrawable() को देखते हैं, तो आप देखेंगे कि यदि आप पृष्ठभूमि के रूप में शून्य पास करते हैं तो यह झंडे को SKIP_DRAW पर सेट करेगा और यही वह है। दूसरी तरफ, यदि कोई ड्रॉइंग ऑब्जेक्ट है, तो यह पृष्ठभूमि पैडिंग सेट अप करने के लिए अतिरिक्त प्रक्रिया के माध्यम से जाएगा।

यहाँ setBackgroundDrawable का कोड है (नोट: उपयोग setBackground setBackgroundDrawable के बजाय)

public void setBackgroundDrawable(Drawable background) { 
    computeOpaqueFlags(); 

    if (background == mBackground) { 
     return; 
    } 

    boolean requestLayout = false; 

    mBackgroundResource = 0; 

    /* 
    * Regardless of whether we're setting a new background or not, we want 
    * to clear the previous drawable. 
    */ 
    if (mBackground != null) { 
     mBackground.setCallback(null); 
     unscheduleDrawable(mBackground); 
    } 

    if (background != null) { 
     Rect padding = sThreadLocal.get(); 
     if (padding == null) { 
      padding = new Rect(); 
      sThreadLocal.set(padding); 
     } 
     resetResolvedDrawables(); 
     background.setLayoutDirection(getLayoutDirection()); 
     if (background.getPadding(padding)) { 
      resetResolvedPadding(); 
      switch (background.getLayoutDirection()) { 
       case LAYOUT_DIRECTION_RTL: 
        mUserPaddingLeftInitial = padding.right; 
        mUserPaddingRightInitial = padding.left; 
        internalSetPadding(padding.right, padding.top, padding.left, padding.bottom); 
        break; 
       case LAYOUT_DIRECTION_LTR: 
       default: 
        mUserPaddingLeftInitial = padding.left; 
        mUserPaddingRightInitial = padding.right; 
        internalSetPadding(padding.left, padding.top, padding.right, padding.bottom); 
      } 
      mLeftPaddingDefined = false; 
      mRightPaddingDefined = false; 
     } 

     // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or 
     // if it has a different minimum size, we should layout again 
     if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || 
       mBackground.getMinimumWidth() != background.getMinimumWidth()) { 
      requestLayout = true; 
     } 

     background.setCallback(this); 
     if (background.isStateful()) { 
      background.setState(getDrawableState()); 
     } 
     background.setVisible(getVisibility() == VISIBLE, false); 
     mBackground = background; 

     if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { 
      mPrivateFlags &= ~PFLAG_SKIP_DRAW; 
      mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; 
      requestLayout = true; 
     } 
    } else { 
     /* Remove the background */ 
     mBackground = null; 

     if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) { 
      /* 
      * This view ONLY drew the background before and we're removing 
      * the background, so now it won't draw anything 
      * (hence we SKIP_DRAW) 
      */ 
      mPrivateFlags &= ~PFLAG_ONLY_DRAWS_BACKGROUND; 
      mPrivateFlags |= PFLAG_SKIP_DRAW; 
     } 

     /* 
     * When the background is set, we try to apply its padding to this 
     * View. When the background is removed, we don't touch this View's 
     * padding. This is noted in the Javadocs. Hence, we don't need to 
     * requestLayout(), the invalidate() below is sufficient. 
     */ 

     // The old background's minimum size could have affected this 
     // View's layout, so let's requestLayout 
     requestLayout = true; 
    } 

    computeOpaqueFlags(); 

    if (requestLayout) { 
     requestLayout(); 
    } 

    mBackgroundSizeChanged = true; 
    invalidate(true); 
} 
संबंधित मुद्दे