1

I want to dynamically draw views using android path. I can create basic shapes using addRect, addOvel, etc. But I want to add complex paths by parsing path from String in xml vector drawable.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="108dp"
    android:height="108dp"
    android:viewportWidth="108"
    android:viewportHeight="108">
    <path android:fillColor="#FF000000" android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z"/>
</vector>

I want to simply use this path data M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z and add it to path in my code, preferably resize to fit to a rectangle.

Even a hint in right direction will be very much helpful for me. Thank you.

Community
  • 1
  • 1
Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
  • Part of Google's vector drawable support is a backport that works on pre-5.0 devices. Presumably, it has code that can parse that sort of data. – CommonsWare Jan 12 '20 at 18:14
  • One of the answers to [this question](https://stackoverflow.com/questions/32588418/is-it-possible-to-create-a-vectordrawable-from-file-system-xml-file) should point you in the right direction. – greeble31 Jan 12 '20 at 18:38

0 Answers0