2013-09-02 6 views
7

के अंत में स्क्रीन पर छवि का कुछ हिस्सा कैसे दिखाया जाए, मैं एक एनीमेशन बना रहा हूं जिसमें एक छवि एक दिशा से दूसरे दिशा में अनुवाद करती है, एनीमेशन स्क्रीन के बाहर छवि के आधा भाग लेता है लेकिन छवि पूर्ण दिखाई देती है एनीमेशन समाप्त होता है। मैं सिर्फ एनीमेशन के बाद छवि का आधा दिखाना चाहता हूं।एनीमेशन

वर्तमान में जब मैं एनीमेशन शुरू करता हूं और एनीमेशन समाप्त होने पर आधा छवि के साथ प्रतिस्थापित करता हूं तो छवि दृश्य में पूर्ण छवि का उपयोग कर रहा हूं लेकिन यह एक छवि परिवर्तन प्रतिबिंब दिखाता है जो मेरी वास्तविक समस्या है जो अजीब दिखता है।

नीचे मेरी एक्सएमएल और कक्षा फ़ाइल है।

एनीमेशन कोड

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration = "2000" 
    android:fillBefore="true" 
    android:fillEnabled="true" 
    android:fromXDelta = "-300%" 
    android:fromYDelta="200%" 
    android:toXDelta="60%"> 

</translate> 

animimv5.setAnimationListener(new AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 
       imv5.setBackgroundResource(R.drawable.img5); 
      } 
      @Override 
      public void onAnimationRepeat(Animation animation) { 

      } 
      @Override 
      public void onAnimationEnd(Animation animation) { 
       imv5.setBackgroundResource(R.drawable.img5_2); 
      } 
     }); 
+1

इस पोस्ट को जांचें: http://stackoverflow.com/questions/3345084/how-can-i-animate-a-view-in-android-and-have-it-stay-in-the-new-position-size fillAfter = true fillEnabled = true – Juangcg

+0

'fillAfter (true)' – Siddhesh

+0

का उपयोग करने का प्रयास करें आप क्या एसडीके लक्षित कर रहे हैं? मैं आपको ऑब्जेक्टएनिमीटर का उपयोग करके एक पूर्ण समाधान पोस्ट कर सकता हूं, लेकिन यह केवल एपीआई स्तर 11 से ही काम करता है। – Ivelius

उत्तर

1

आप निम्न हो सकता है की कोशिश:

एक्सएमएल (यह पैरामीटर सेट करने के लिए जोड़) android:fillAfter में

या वर्ग स्रोत में संबंधित विधि का उपयोग कर setFillAfter(boolean)

सही पर सेट जब , एनीमेशन समाप्त हो जाने के बाद एनीमेशन परिवर्तन लागू किया गया है। प्रलेखन के अनुसार here सत्य पर सेट होने पर, एनीमेशन समाप्त हो जाने के बाद एनीमेशन परिवर्तन लागू होता है। मूल मूल्य गलत है। अगर fillEnabled सत्य पर सेट नहीं है और एनीमेशन दृश्य पर सेट नहीं है, तो fillAfter सत्य माना जाता है।

अतिरिक्त युक्तियों के लिए

और व्याख्याएं देखें Chet's blog post

आशा है कि यह मदद करता है ..;)

0

ये रहा, सर:

MainActivity : 

    public class MainActivity extends Activity { 

    private View animatedView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     animatedView = findViewById(R.id.view); 
    } 

    public void animate(View view) { 
     int targetX = ((View) animatedView.getParent()).getWidth() - animatedView.getWidth()/2; 
     ObjectAnimator.ofFloat(animatedView, "x", 0, targetX).setDuration(1000).start(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 

लेआउट एक्सएमएल:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       tools:context=".MainActivity"> 

    <TextView 
      android:id="@+id/view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#CC0000" 
      android:padding="30dp" 
      android:textColor="@android:color/white" 
      android:text="@string/hello_world"/> 
    <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Animate" 
      android:onClick="animate" 
      android:id="@+id/button" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true"/> 

</RelativeLayout>