2016-12-06 1 views
0

애니메이션 벡터 드로어 블 here을 사용하려면 Android 가이드 라인을 따르십시오. 나는 (img_logo.xml)AnimatedVectorDrawable에 애니메이션이 표시되지 않습니다. API 21+

애니메이션 벡터 당김 XML 파일

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/ic_logo" > 
    <target 
     android:name="rotationGroup" 
     android:animation="@anim/rotate" /> 
    <target 
     android:name="v" 
     android:animation="@anim/anim_path" /> 
</animated-vector> 

및 이미지 뷰

<ImageView 
     android:id="@+id/img_logo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:elevation="@dimen/view_elevation" 
     android:layout_marginBottom="@dimen/activity_horizontal_margin"/> 
로 설정 안드로이드 벡터 스튜디오 를 사용하여 XML 벡터 파일을 만들었습니다

또한 아래 코드를 사용하여 코드에서 애니메이션을 시도했습니다 here

AnimatedVectorDrawable d = (AnimatedVectorDrawable) getDrawable(R.drawable.anim_logo); // Insert your AnimatedVectorDrawable resource identifier 
mImageView.setImageDrawable(d); 
d.start(); 

Belom 애니메이션 XML anim_path.xml 있습니다

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <objectAnimator 
     android:duration="1000" 
     android:propertyName="pathData" 
     android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z" 
     android:valueTo="M300,70 l 0,-70 70,0 0,140 -70,0 z" 
     android:valueType="pathType" /> 
</set> 

rotate.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <objectAnimator 
     android:duration="1000" 
     android:propertyName="rotation" 
     android:valueFrom="0" 
     android:valueTo="360" /> 
</set> 
당신이 here

01,235,164에서 벡터 당김을 찾을 수 있습니다

가이드에 언급 된대로 모든 것을 설정했지만 앱을 실행하면 이미지에 애니메이션이 적용되지 않습니다. 어떤 도움을 주셔서 감사합니다.

+0

충분한 정보가 여기에 있다고 생각하지 마십시오. VectorDrawable 및 Animators의 xml은 무엇입니까? 화면에서 무엇을 볼 수 있습니까? 오류 메시지가 있습니까? –

+0

@LewisMcGeary 업데이트 된 질문을 확인하십시오. –

답변

0

먼저 VectorDrawable은 상당히 크고 복잡합니다. 이렇게하면 작동이 멈추지 않아야하지만 성능이 저하 될 수 있습니다. 참고로 문서에 200dp x 200dp as the maximum size을 권장합니다.

그러나 이것이 작동하는 애니메이션이 아닌 이유는 AnimatedVectorDrawable이 존재하지 않는 VectorDrawable의 부분을 대상으로하려고하기 때문입니다. 라인에서 :

<target 
     android:name="rotationGroup" 
     android:animation="@anim/rotate" /> 
    <target 
     android:name="v" 
     android:animation="@anim/anim_path" /> 

대상 이름은 우리가 그들을 찾아 낼 것으로 예상 할 것 VectorDrawable 그렇게 어딘가에, 각 애니메이션을 적용 할 VectorDrawable의 어느 부분을 지정하지 :

<group 
     android:name="rotationGroup" 
     ... 

    <path 
     android:name="v" 
     ... 

을하지만 더있다 의도 한 대상과 일치하는 이름을 가진 VectorDrawable의 일부입니다. 따라서 작업 애니메이션을 만들려면이를 수정해야합니다.

관련 문제