java - change corner radius of drawable programmatically -


मुझे यह आकार एक XML में परिभाषित किया गया है:

  & lt;? Xml version = " 1.0 "एन्कोडिंग =" यूटीएफ -8 "? & Gt; & Lt; आकार xmlns: एंड्रॉइड = "http://schemas.android.com/apk/res/android" एंड्रॉइड: आकृति = "आयत" & gt; & Lt; ढाल एंड्रॉइड: startColor = "# FFFF0000" एंड्रॉइड: एंडColor = "# 80FF00FF" एंड्रॉइड: एंगल = "45" / & gt; & Lt; padding android: left = "7dp" android: top = "7dp" एंड्रॉइड: right = "7dp" एंड्रॉइड: bottom = "7dp" / & gt; & LT; कोनों एंड्रॉयड: bottomLeftRadius = "5dp" ## इस एंड्रॉयड बदलने की जरूरत: topLeftRadius = "5dp" ## इस एंड्रॉयड बदलने की जरूरत: bottomRightRadius = "5dp" ## इस एंड्रॉयड बदलने की जरूरत topRightRadius = "5dp" / & gt; ## इस जरूरत को बदलने & lt; / shape & gt;   

मैं निम्नलिखित वस्तु बनाने हूँ:।

<कोड> Drawable आकार = getResource () getDrawable (R.drawable.myshape);

और मुझे इसकी त्रिज्या को संशोधित करने की आवश्यकता है (या एक और कोने त्रिज्या के साथ एक बनाओ)।

मैं त्रिज्या कैसे बदल सकता हूँ? कैसे मैं आकार प्रोग्राम के रूप में बना सकते हैं?

मैं मेरी समस्या हल। यहाँ समाधान है:

  निजी Drawable getShape () {GradientDrawable gradientDrawable = नए GradientDrawable (GradientDrawable.Orientation.TL_BR, नई पूर्णांक [] {startColor, centerColor, endColor}); gradientDrawable.setGradientType (GradientDrawable.LINEAR_GRADIENT); gradientDrawable.setCornerRadii (getRandomFloatArray ()); ग्रेडिएंट ड्रेवायबल .सेटग्रेडिएन्ट सेंटर (0.0 एफ, 0.45 एफ); रिटर्न ग्रेडिएंट ड्रॉएबल; } निजी फ्लोट [] getRandomFloatArray () {यादृच्छिक rnd = नया रैंडम (); फ्लोट [] फ़्लोट्स = नया फ्लोट [8]; के लिए (इंट i = 0; i & lt; floats.length; i ++) {फ्लोट [i] = rnd.nextInt (45); } वापसी फ्लोट; }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -