2012-12-21 6 views
6

मैं किसी अन्य सर्कल के भीतर एक छोटा सर्कल खींचने की कोशिश कर रहा हूं। यह बहुत आसान लगता है लेकिन मुझे इसके साथ परेशानी हो रही है और एक जवाब नहीं मिला। कोड का उपयोग कर im है:किसी अन्य आकार के अंदर एक छोटे आकार के ड्रॉ को कैसे आकर्षित करें प्रोग्रामेटिक रूप से

ShapeDrawable biggerCircle= new ShapeDrawable(new OvalShape()); 
    biggerCircle.setIntrinsicHeight(60); 
    biggerCircle.setIntrinsicWidth(60); 
    biggerCircle.setBounds(new Rect(0, 0, 60, 60)); 
    biggerCircle.getPaint().setColor(Color.BLUE); 

    ShapeDrawable smallerCircle= new ShapeDrawable(new OvalShape()); 
    smallerCircle.setIntrinsicHeight(10); 
    smallerCircle.setIntrinsicWidth(10); 
    smallerCircle.setBounds(new Rect(0, 0, 10, 10)); 
    smallerCircle.getPaint().setColor(Color.BLACK); 
    smallerCircle.setPadding(50,50,50,50); 

    LayerDrawable composite1 = new LayerDrawable(new Drawable[] biggerCircle,smallerCircle,}); 

लेकिन वह फ्लॉप काम, क्या होता है कि छोटे वृत्त बड़ा चक्र के रूप में के रूप में बड़ा हो जाता है। तो एकमात्र चीज बड़ी सर्कल के आकार के साथ काले सर्कल के रूप में दिख रही है। अगर कोई मदद कर सकता है तो मैं क्षमा करूँगा। अग्रिम में धन्यवाद।

उत्तर

18

बदलें आदेश,

Drawable[] d = {smallerCircle,biggerCircle}; 

LayerDrawable composite1 = new LayerDrawable(d); 

इस

 ShapeDrawable biggerCircle= new ShapeDrawable(new OvalShape()); 
     biggerCircle.setIntrinsicHeight(60); 
     biggerCircle.setIntrinsicWidth(60); 
     biggerCircle.setBounds(new Rect(0, 0, 60, 60)); 
     biggerCircle.getPaint().setColor(Color.BLUE); 

     ShapeDrawable smallerCircle= new ShapeDrawable(new OvalShape()); 
     smallerCircle.setIntrinsicHeight(10); 
     smallerCircle.setIntrinsicWidth(10); 
     smallerCircle.setBounds(new Rect(0, 0, 10, 10)); 
     smallerCircle.getPaint().setColor(Color.BLACK); 
     smallerCircle.setPadding(50,50,50,50); 
     Drawable[] d = {smallerCircle,biggerCircle}; 

     LayerDrawable composite1 = new LayerDrawable(d); 

     btn.setBackgroundDrawable(composite1); 
तरह की कोशिश

enter image description here

+0

जवाब के लिए धन्यवाद, लेकिन मैं tryed और यह अभी भी एक ही बात होता है। – Alan

+0

संपादन pls को देखो, मैंने कोशिश की है कि यह मेरे लिए काम करता है – Talha

+0

अन्य लोगों के लिए जो इसे पढ़ेंगे, सिर्फ यह ध्यान दें कि छोटा सर्कल वास्तव में बड़ा सर्कल है। मैं smaler सर्कल में setPadding का उपयोग कर रहा था और चारों ओर एक और तरीका होना चाहिए। उत्तर के लिए बहुत बहुत धन्यवाद। – Alan

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