2011-09-07 12 views
16

मुझे कोई समस्या है। मैं रंग के रूप में ढाल के साथ एक टेक्स्टव्यू देखना चाहता हूं। और इसके पीछे एक काला छाया। समस्या यह है कि छाया नामक रंग का उपयोग करने का जगह में ढाल के रंग का उपयोग कर रहा है (Color.BLACK)टेक्स्ट व्यू ढाल और छाया जोड़ना

मेरे कोड है: numberTextView = (TextView)findViewById(R.id.something);

Shader textShaderTop = new LinearGradient(0, 30, 0, 60, 
       new int[]{Color.parseColor("#A6A6A6"), Color.parseColor("#E8E8E8"), Color.parseColor("#A6A6A6")}, 
       new float[]{0, 0.5f, 1}, TileMode.CLAMP); 
    numberTextView.getPaint().setShader(textShaderTop); 

    numberTextView.setShadowLayer(
       0.1f, //float radius 
       20f, //float dx 
       20f, //float dy 
       Color.BLACK //this is not black on the screen, but it uses the gradient color!? 
      ); 

किसी को क्या करना है जानता है

उत्तर

17

मेरे साथ भी ठीक यही समस्या आई. मैंने टेक्स्ट व्यू को विस्तारित करके और ड्रा विधि को ओवरराइड करके इसे ठीक करने में कामयाब रहे। यहाँ यह कैसे की तरह

@Override 
protected void onDraw(Canvas canvas) { 
    // draw the shadow 
    getPaint().setShadowLayer(1, 1, 1, 0xbf000000); // or whatever shadow you use 
    getPaint().setShader(null); 
    super.onDraw(canvas); 

    // draw the gradient filled text 
    getPaint().clearShadowLayer(); 
    getPaint().setShader(new LinearGradient(0, getHeight(), 0, 0, 0xffacacac, 0xffffffff, TileMode.CLAMP)); // or whatever gradient/shader you use 
    super.onDraw(canvas); 
} 

हालांकि इस विधि शायद आप अपनी ढाल में पारदर्शिता के साथ रंगों का उपयोग करना चाहते हैं तो काम नहीं करेगा दिखता है।

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