2011-03-11 15 views
5

मैं अपने एंड्रॉइड एप्लिकेशन के लिए एक गतिशील आइकन मेनू बनाने की कोशिश कर रहा हूं। आइकन 2 ड्रॉबल, 9-पैच पृष्ठभूमि छवि से बना है जिसमें आइकन छवि ओवरले है।एंड्रॉइड: ओवरले छवि पृष्ठभूमि में पैडिंग सेट करना

overlay two images in android to set an imageview के संदर्भ में, मेरे पास निम्न कोड है जो ओवरले अच्छी तरह से है।

 Resources res = parent.getResources(); 
     Drawable icon_bg = res.getDrawable(R.drawable.menu_icon_bg); 
     Drawable icon = res.getDrawable(R.drawable.menu_icon); 

     // Not working 
     int int_icon_height = icon.getIntrinsicHeight(); 
     int int_icon_width = icon.getIntrinsicWidth(); 
     Rect rect_icon_bg_bound = new Rect(); 
     rect_icon_bg_bound.left = 0;//(int) Math.round(int_icon_width*-1.5); 
     rect_icon_bg_bound.right = (int) Math.round(int_icon_width*1.5); 
     rect_icon_bg_bound.top = 0;//(int)Math.round(int_icon_height*-1.5); 
     rect_icon_bg_bound.bottom = (int)Math.round(int_icon_height*1.5); 
     icon_bg.setBounds(rect_icon_bg_bound); 

     Drawable[] layers = new Drawable[2]; 
     layers[0] = icon_bg; 
     layers[1] = icon; 

     LayerDrawable layerDrawable = new LayerDrawable(layers); 
     ImageView iv_icon_combined = new ImageView(getApplicationContext()); 
     iv_icon_combined.setImageDrawable(layerDrawable); 

जिस समस्या का मैं सामना कर रहा हूं वह अभी एक पैडिंग जोड़ रहा है ताकि आइकन पृष्ठभूमि में कुछ अंतर रखे।

आशा है कि यहां कुछ ज्ञान प्राप्त करें, अग्रिम धन्यवाद।

+0

हाय, मैं अभी भी इस प्रश्न पर फंस गया हूं। क्या कोई और जगह है जहां मैं इसमें मदद करने के लिए देख सकता हूं? – InSheNaiDe

उत्तर

5

मैं बस इसी मुद्दे में भाग गया। LayerDrawable पर setLayerInset विधि पर एक नज़र डालें। यह लेयर लेवल को तर्क के रूप में लेता है और फिर ड्रॉइंग के बाएं, ऊपर, दाएं, नीचे की सीमाओं के लिए संशोधक।

+0

बहुत बहुत धन्यवाद। यह चलेगा!! – InSheNaiDe

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