2013-03-09 2 views
5

मैं दो एनिमेशन का एक सेट है, दोनों एक साथ एनिमेशन overshoot क्षेपकएंड्रॉइड समवर्ती इंटरपोलेटर का उपयोग करना संभव है?

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/overshoot_interpolator" > 

    <translate 
     android:duration="6000" 
     android:fromXDelta="100%" android:toXDelta="0%" /> 

    <scale 
     android:duration="6000" 
     android:fromXScale="1.0" android:toXScale="0.6" 
     android:pivotX="0" 
     android:fromYScale="1.0" android:toYScale="1.0" 
     android:repeatCount="1" 
     android:repeatMode="reverse" /> 
</set> 

मैं translate एनीमेशन लक्ष्य के पार चले चाहते हैं, और scale एनीमेशन तेजी लाने के लिए उपयोग कर रहा चलाते हैं।
मैं यह करने की कोशिश की, लेकिन यह काम नहीं करता है:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <translate 
     android:interpolator="@android:anim/overshoot_interpolator" 
     android:duration="6000" 
     android:fromXDelta="100%" android:toXDelta="0%" /> 

    <scale 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:duration="6000" 
     android:fromXScale="1.0" android:toXScale="0.6" 
     android:pivotX="0" 
     android:fromYScale="1.0" android:toYScale="1.0" 
     android:repeatCount="1" 
     android:repeatMode="reverse" /> 
</set> 

ऐसा लगता है जैसे कि केवल एक क्षेपक सभी एनिमेशन के लिए एक निश्चित समय एक ही लक्ष्य पर किया जा रहा है पर सक्रिय किया जा सकता।

उत्तर

3

मैंने एनिमेशन को विभाजित किया और ImageView पर एक और दूसरे को RelativeLayout पर रखा जिसमें छवि दृश्य था।

अनुवादक

<?xml version="1.0" encoding="utf-8"?> 

<set xmlns:android="http://schemas.android.com/apk/res/android"> 

    <translate 
      android:interpolator="@android:anim/overshoot_interpolator" 
      android:duration="6000" 
      android:fromXDelta="100%" android:toXDelta="0%" /> 

</set> 

Scalor

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <scale 
      android:interpolator="@android:anim/accelerate_interpolator" 
      android:duration="6000" 
      android:fromXScale="1.0" android:toXScale="0.6" 
      android:pivotX="0" 
      android:fromYScale="1.0" android:toYScale="1.0" 
      android:repeatCount="1" 
      android:repeatMode="reverse" /> 
</set> 

एक्सएमएल

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/previousItem" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        android:onClick="goToPreviousItem" 
        android:layout_margin="@dimen/float_from_edges" 
        android:layout_width="wrap_content" 
      > 
     <ImageView android:id="@+id/previousItemArrow" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/arrow_left" 
       /> 
    </RelativeLayout> 

और स्रोत कोड यह भड़काना करने के लिए:

RelativeLayout previousItemButton = (RelativeLayout)findViewById(R.id.previousItem); 
    ImageView myButton = (ImageView)findViewById(R.id.previousItemArrow); 
    Animation translator = 
      AnimationUtils.loadAnimation(this, R.anim.translator); 
    myButton.startAnimation(translator); 

    Animation scalor = 
      AnimationUtils.loadAnimation(this, R.anim.scalor); 
    previousItemButton.startAnimation(scalor); 

मैंने सोचा कि यह बहुत अच्छा लग रहा था। मुझे यकीन नहीं है कि आप किस प्रभाव की उम्मीद कर रहे थे।

9

यह केवल अनुमान है। मुझे याद है कि AnimationSet के निर्माता एक तर्क ले सकते हैं, अर्थात् शेयरइंटरपोलेटर

पैरामीटर के नाम से निर्णय लेते हुए, यह शायद आपके मामले में गलत पर सेट होना चाहिए। अभी, यह डिफ़ॉल्ट "मान" का उपयोग करना चाहिए। यह डिफ़ॉल्ट मान शायद सच है क्योंकि आपके एनिमेशन में अलग-अलग इंटरपोलेटर नहीं हैं, हालांकि आपने प्रत्येक के लिए एक अलग निर्दिष्ट किया है।

इस बात की पुष्टि करने के लिए, AnimationSet के स्रोत कोड (xml से) shareInterpolator के लिए एक मूल्य निर्दिष्ट निम्न पंक्ति है:

setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK, 
     a.getBoolean(com.android.internal.R.styleable.AnimationSet_shareInterpolator 
      , true)); 

यह स्पष्ट रूप से मतलब है कि अगर यह बूलियन निर्दिष्ट नहीं है, यह सच लागू हो जाएगी ।


समाधान

आपकी समस्या का समाधान करने के लिए, मैं तुम्हें इस "R.styleable.AnimationSet_shareInterpolator" का उपयोग कर इसे निर्दिष्ट करना चाहिए लगता है। यह केवल इसका मतलब है android:shareInterpolator="false"जोड़ने अपने<set>तत्वों को

1
This xml works with both interpolators check this 


<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shareInterpolator="false"> 

    <translate 
     android:interpolator="@android:anim/overshoot_interpolator" 
     android:fromXDelta="100%" android:toXDelta="0%" 
     android:duration="500" /> 

    <scale 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:fromXScale="1.0" android:toXScale="0.6" 
     android:pivotX="0" 
     android:fromYScale="1.0" android:toYScale="1.0" 
     android:repeatCount="1" 
     android:repeatMode="reverse" 
     android:startOffset="500" 
     android:duration="1000" /> 
</set> 
संबंधित मुद्दे