2016-04-23 27 views
6

我剛開始在矢量繪製中使用剪輯路徑。我想旋轉剪輯路徑,但不能在任何路徑中旋轉任何路徑,因此它可能具有pivotX和pivotY屬性。但是,當放在一個組中時,它不會再剪輯組外的路徑(因此變得毫無用處)。有沒有解決方法?這是我的繪製(在這種狀態下,裁剪不因爲什麼,我提到的工作):Android可繪製的剪輯路徑圖層是否可以旋轉?

<!-- drawable/bluetooth_audio.xml --> 
<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:height="48dp" 
    android:width="48dp" 
    android:viewportWidth="24" 
    android:viewportHeight="24"> 

    <group 
     android:name="maskGroup" 
     android:pivotX="12" 
     android:pivotY="12"> 

     <clip-path 
      android:name="mask" 
      android:pathData="M12,0 V12 H24 V24 H0 V0"/> 

    </group> 

    <group 
     android:name="base" 
     android:pivotX="12" 
     android:pivotY="12"> 
     <path 
      android:fillColor="#FFF" 
      android:pathData="M12.88,16.29L11,18.17V14.41M11,5.83L12.88,7.71L11,9.58M15.71,7.71L10,2 
      H9V9.58L4.41,5L3,6.41L8.59,12L3,17.58L4.41,19L9,14.41V22H10L15.71,16.29L11.41,12M19.53,6.71L18.26,8M14.24,12L16.56,14.33C16.84,13.6 17,12.82 17,12C17,11.18 16.84,10.4 16.57,9.68L14.24,12Z"/> 
     <path 
      android:fillColor="#FFF" 
      android:pathData=" 
      M18.26,8 
      C18.89,9.18 19.25,10.55 19.25,12 
      C19.25,13.45 18.89,14.82 18.26,16 
      L19.46,17.22 
      C20.43,15.68 21,13.87 21,11.91 
      C21,10 20.46,8.23 19.53,6.71 
      " 
      /> 

    </group> 
</vector> 

回答

1

其實路徑和夾路徑是用於不同的目的。

剪輯路徑:用於獲取Canvas或用於繪製視圖端口。

路徑:用於在該視圖上渲染繪畫端口。

因此,不要使用剪輯路徑來繪製圖形或動畫。如果在裁剪路徑之外繪製的任何東西都不會被渲染或顯示。 Ref:http://veloveloper.mozilla.org/en/docs/cz/SVG/Element/clipPath

+0

我看到的Android工程師誰用夾路徑創建動畫的視頻......據我所知,剪輯路徑用於棒棒糖上的動畫(快速設置圖標)。如果剪輯路徑不是我應該使用的工具,那是什麼?什麼是實現這種類型的動畫的工具? –

0

如果開始和結束狀態都具有相同數量的pathData步驟,則可以對剪輯路徑的更改進行動畫設置;也許不是「旋轉」剪輯路徑,而是定義「旋轉」剪輯路徑的結束狀態,然後爲剪輯路徑設置動畫效果?該objectAnimator應用看起來是這樣的:

<objectAnimator 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:propertyName="pathData" 
android:valueFrom="M18 37 L38 37 L38 37 L18 37 Z" 
android:valueTo="M0 0 L56 0 L56 56 L0 56 Z" 
android:duration="600" 
android:interpolator="@android:interpolator/fast_out_slow_in" 
android:valueType="pathType" /> 

編輯:Android文檔

的AnimatedStateListDrawable類可以創建可繪製,展示了相關的視圖狀態的變化之間的動畫中找到的。 Android 5.0中的一些系統小部件默認使用這些動畫。以下示例顯示如何將AnimatedStateListDrawable定義爲XML資源:

AnimatedStateListDrawable類允許您創建可在相關視圖的狀態更改之間顯示動畫的可繪製對象。 Android 5.0中的一些系統小部件默認使用這些動畫。下面的示例演示如何定義一個AnimatedStateListDrawable作爲XML資源:

<!-- res/drawable/myanimstatedrawable.xml --> 
<animated-selector 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- provide a different drawable for each state--> 
<item android:id="@+id/pressed" 
android:drawable="@drawable/drawableP" 
    android:state_pressed="true"/> 
<item android:id="@+id/focused" 
android:drawable="@drawable/drawableF" 
    android:state_focused="true"/> 
<item android:id="@id/default" 
    android:drawable="@drawable/drawableD"/> 

<!-- specify a transition --> 
<transition android:fromId="@+id/default" 
android:toId="@+id/pressed"> 
    <animation-list> 
     <item android:duration="15" 
android:drawable="@drawable/dt1"/> 
     <item android:duration="15" 
android:drawable="@drawable/dt2"/> 
     ... 
    </animation-list> 
</transition> 
... 
</animated-selector> 

https://developer.android.com/reference/android/graphics/drawable/AnimatedStateListDrawable.html

https://developer.android.com/training/material/animations.html#Transitions