Thursday, February 11, 2016

Android: How to change size of vector drawable image


Android 5.0 brought support for vector drawables similar to SVG. The lack of backwards compatibility with older versions of Android has probably seen a slow uptake in using it, but the recent addition of vector assets to Android Studio helps to conquer that hurdle illustrates the belief Google have in the merits of wide adoption of vector graphics by Android apps.

It should be noted that the Lollipop support for vector drawables had some kinks which have been ironed out in later Android releases. Most notably in Lolipop scaled vector drawables appear aliased.
from api v23 (Marshmallow) they scale just fine.

So if you do manage to end up in a situation where you want to scale a vector drawable (i.e. your app is only supporting v23+) then the following example (where the icon is by default 24 x 24) is one way to do it.

<ImageView    android:id="@+id/icon"    android:layout_width="240dp"    android:layout_height="240dp"    android:layout_alignParentLeft="true"    android:src="@drawable/my_test_vector"    />

VectorDrawable vectorDrawable = (VectorDrawable) mIconImageView.getDrawable();
vectorDrawable.setTint(Color.WHITE);
vectorDrawable.setBounds(0,0,mIconImageView.getWidth(),mIconImageView.getHeight());

29 comments:

  1. It is very useful to know about how to change the size of vector. thank you for sharing the blog with us.
    JAVA TRAINING

    ReplyDelete
  2. Thanks a lot for all your valuable article! We are really happy about the your...
    hadoop Training in Chennai

    ReplyDelete
  3. These information really worth saying, i think you are master of the content and thank you so much sharing that valuable information and get new skills after refer that post.
    informatica

    ReplyDelete
  4. Awesome..You have clearly explained ...Its very useful for me to know about new things..Keep on blogging..
    Java Training in Chennai

    ReplyDelete
  5. You have clearly explained about How to change size of vector drawable image..Its very useful and informative..Keep on sharing..
    Java Training in Chennai

    ReplyDelete
  6. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work


    SEO Training in Chennai

    ReplyDelete
  7. I really very nice articles and great effort contents of blog.I clearly watch the android apps its amazing apps. Its useful for you.


    Java training in Chennai

    ReplyDelete
  8. Thank you for sharing the information here. Its much informative and really i got some valid information. You had posted the amazing article.

    Dotnet Training in Chennai

    ReplyDelete
  9. this content is really useful and you have done a tremendous work ,it is really awesome and it is good too.


    php Training in Chennai

    ReplyDelete
  10. Superb i really enjoyed very much with this article here. Really its a amazing article i had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.


    SAP training in Chennai

    ReplyDelete
  11. In the site was very excellent,i think this is very best one compare others and then the more information to get after read this post.

    hadoop

    ReplyDelete
  12. I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

    SAP training in Chennai

    ReplyDelete
  13. Everything is fine, am happy about your blog. Thanks admin for sharing the unique content, you have done a great job I appreciate your effort and I hope you will get more positive comments from the web users.


    SAP training in Chennai

    ReplyDelete

  14. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks!


    SAP training in Chennai

    ReplyDelete
  15. Great and useful article. Creating content regularly is very tough. Your points are motivated me to move on.


    SEO Company in Chennai

    ReplyDelete
  16. Really nice information you had posted. Its very informative and definitely it will be useful for many people

    Email Marketing Chennai

    ReplyDelete
  17. Useful post.You have told another data which is useful and i assembled learning about this subject so please overhaul data more upgrade this theme.
    Regards,
    Informatica Training Institute in Chennai | Informatica Training center Chennai

    ReplyDelete
  18. Thank you for taking time to provide us some of the useful and exclusive information with us.
    Regards,
    dotnet courses in Chennai | .net training Chennai | .net course in Chennai

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,

    Core JAVA Training in Chennai | JAVA Training in Chennai

    ReplyDelete
  21. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Regards,

    PHP Training in Chennai | Webdesigning Training in Chennai

    ReplyDelete

  22. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
    Regards,'
    Performance Tuning Training in Chennai | Oracle PL/SQL Training in Chennai

    ReplyDelete
  23. Nice content with valuable information. Thanks for sharing.
    Java Training institute in Velachery

    ReplyDelete
  24. Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for whose looking this precious information to developing their skill.
    Regards,
    Best DOT NET Training in Chennai|DOT NET Training in Chennai|DOT NET Course in Chennai

    ReplyDelete
  25. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  26. Very useful information in this article! its really useful for Java development company, but we request new updated article as ASP.NET reached one notch up

    ReplyDelete