2

drawable을 표시하고 터치를 감지하는 사용자 정의 view이 있습니다. 그것은 내가 vectordrawable로 각각 SVG 벡터 그래픽을 변환 리소스로 텍스트를 설정할 수 있도록하려면 한벡터 드로어 블에서 텍스트에 액세스하거나 번역하는 방법

Hello in a box!

예를 들어, 텍스트를 포함하는 일부 drawable 층의 번호를 가지고 그래서 저는 다른 번역본으로 대체 할 수 있습니다.

위의 '안녕 상자'에 대한 SVG의 XML 코드 : -

<svg 
    width="800" 
    height="400" 
    viewBox="0 0 800 400.00001" 
    id="svg5772" 
    version="1.1" 
    inkscape:version="0.91 r13725" 
    sodipodi:docname="HELLO in a box.svg"> 
    <defs 
    id="defs5774" /> 
    <sodipodi:namedview 
    id="base" 
    pagecolor="#ffffff" 
    bordercolor="#666666" 
    borderopacity="1.0" 
    <rect 
     style="opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" 
     id="rect6320" 
     width="468.57144" 
     height="128.57143" 
     x="174.28572" 
     y="786.64795" 
     rx="0" 
     ry="0" /> 
    <text 
     xml:space="preserve" 
     style="font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" 
     x="348.57141" 
     y="869.50507" 
     id="text6322" 
     sodipodi:linespacing="125%"><tspan 
     sodipodi:role="line" 
     id="tspan6324" 
     x="348.57141" 
     y="869.50507">HELLO!!!</tspan></text> 
    </g> 
</svg> 

는 ...이 vectordrawable XML로 변환 : -

<?xml version="1.0" encoding="utf-8"?> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:viewportWidth="800" 
    android:viewportHeight="400" 
    android:width="800dp" 
    android:height="400dp"> 
    <group 
     android:translateY="-652.3621"> 
     <path 
      android:pathData="M174.28572 786.64795l468.57144 0 0 128.57143 -468.57144 0z" 
      android:strokeWidth="2" 
      android:fillColor="#ffffff" 
      android:strokeLineJoin="round" 
      android:strokeLineCap="round" 
      android:strokeMiterLimit="4" 
      android:strokeColor="#000000" /> 
     <path 
      android:pathData="M374.72375 869.50507l-3.86718 0 0 -14.23829 -14.51172 0 0 14.23829 -3.86719 0 0 -29.08204 3.86719 0 0 11.40625 14.51172 0 0 -11.40625 3.86718 0 0 29.08204z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M401.71594 869.50507l-19.16015 0 0 -29.08204 19.16015 0 0 3.4375 -15.29297 0 0 7.96875 15.29297 0 0 3.4375 -15.29297 0 0 10.80079 15.29297 0 0 3.4375z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M426.26672 869.50507l-18.39843 0 0 -29.08204 3.86718 0 0 25.64454 14.53125 0 0 3.4375z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M448.53235 869.50507l-18.39844 0 0 -29.08204 3.86719 0 0 25.64454 14.53125 0 0 3.4375z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M473.6886 843.76288q1.77734 1.95312 2.71484 4.78515 0.95703 2.83204 0.95703 6.42579 0 3.59375 -0.97656 6.44531 -0.95703 2.83203 -2.69531 4.72656 -1.79688 1.97266 -4.25781 2.96875 -2.44141 0.99609 -5.58594 0.99609 -3.06641 0 -5.58594 -1.01562 -2.5 -1.01563 -4.25781 -2.94922 -1.75781 -1.93359 -2.71485 -4.74609 -0.9375 -2.8125 -0.9375 -6.42578 0 -3.55469 0.9375 -6.36719 0.9375 -2.83203 2.73438 -4.84375 1.71875 -1.91406 4.25781 -2.92969 2.5586 -1.01562 5.56641 -1.01562 3.125 0 5.60547 1.03515 2.5 1.01563 4.23828 2.91016zm-0.35156 11.21094q0 -5.66407 -2.53907 -8.73047 -2.53906 -3.08594 -6.93359 -3.08594 -4.43359 0 -6.97266 3.08594 -2.51953 3.0664 -2.51953 8.73047 0 5.72265 2.57813 8.76953 2.57812 3.02734 6.91406 3.02734 4.33594 0 6.89453 -3.02734 2.57813 -3.04688 2.57813 -8.76953z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M489.64563 840.42303l-0.50781 21.07422 -3.32032 0 -0.54687 -21.07422 4.375 0zm-0.19531 29.08204l-3.98438 0 0 -4.1211 3.98438 0 0 4.1211z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M505.42688 840.42303l-0.50781 21.07422 -3.32032 0 -0.54687 -21.07422 4.375 0zm-0.19531 29.08204l-3.98438 0 0 -4.1211 3.98438 0 0 4.1211z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
     <path 
      android:pathData="M521.20813 840.42303l-0.50781 21.07422 -3.32032 0 -0.54687 -21.07422 4.375 0zm-0.19531 29.08204l-3.98438 0 0 -4.1211 3.98438 0 0 4.1211z" 
      android:strokeLineCap="butt" 
      android:fillColor="#000000" 
      android:strokeLineJoin="miter" /> 
    </group> 
</vector> 

는 각각의 편지처럼 매우 보인다 "여보세요!!!" 텍스트는 path으로 변환되어 canvas으로 직접 그려집니다.

내 질문은 텍스트가 포함 된 벡터 그래픽을 canvas에 표시하는 대신 텍스트 부분에 리소스를 사용할 수있는 방법이 있습니까? 아니면 각 언어마다 다른 그래픽을 만들겠습니까?

답변

4

귀하의 결론은 옳습니다.

벡터 드로어 블은 완전히 경로 기반입니다. 이는 경로 만 변경되기 때문에 애니메이션의 근본적인 원인입니다. 따라서 그들은 텍스트 나 이미지를 입력으로 사용하지 않습니다.

옵션으로 .svg 텍스트 (일부 도구 일 수도 있습니다?)를 가져온 다음 각 언어에 대해 xml로 변환 할 수 있습니다. 보다 큰 지역화를 목표로 삼고 있다면 벡터 드로어 블이 올바른 접근 방식이 아닐 수도 있습니다.

1

지역화 가능 콘텐츠와 드로어 블을 구분하는 접근 방식을 사용해야합니다.

정확히 무엇을하고 있는지는 명확하지 않지만, 예를 들어 사용자 정의 버튼을 원한다면 VectorDrawable을 사용자 정의 버튼 디자인으로 만들어야합니다. 그런 다음 드로어 블을 TextView의 배경으로 사용하거나 텍스트 부분을 TextView으로 겹쳐서 ImageView 위에 겹쳐서 넣으십시오.

관련 문제