2012-12-25 16 views
6

के लिए स्लाइड इन और स्लाइड आउट एनीमेशन मेरे पास LinearLayout, I am dynamically adding TextView, ImageView to that LinearLayout है, अब मैंने इन टेक्स्ट व्यू और इमेज व्यू में ऑनक्लिक लिस्टनर जोड़ा है।एक लेआउट

मेरे पास एक सरणीसूची है जिसमें लूप का उपयोग करके इसमें 10 आइटम हैं, मुझे प्रत्येक मान और प्रदर्शन मिल रहा है, क्योंकि यह क्विज़ ऐप है, मेरे पास अगले और पिछले बटन हैं, जब मैं उस पर क्लिक करता हूं तो मैं एक-एक करके आइटम प्रदर्शित कर रहा हूं सरणी सूची से। Now I need slide In and slide Out animation to apply to this Linear Layout.

मैं इस देखा है:

Link 1

Link 2

और यह भी मैं इस

slideIn = new TranslateAnimation(
       TranslateAnimation.RELATIVE_TO_PARENT, 1.0f, 
       TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, 
       TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, 
       TranslateAnimation.RELATIVE_TO_PARENT, 0.0f); 

     slideIn.setDuration(500); 
     slideOut = new TranslateAnimation(
       TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, 
       TranslateAnimation.RELATIVE_TO_PARENT, -1.0f, 
       TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, 
       TranslateAnimation.RELATIVE_TO_PARENT, 0.0f); 

     slideOut.setDuration(500); 

लेकिन नहीं की कोशिश की है काम कर कृपया इस पर मदद करते हैं।

संपादित करें:

समस्या: मैं रेखीय लेआउट को यह आवेदन किया है लेकिन क्या होता है कि जब मैं अगले बटन पर क्लिक करें वर्तमान प्रश्न छोड़ दिया स्लाइड हो जाएगा और एक खाली स्क्रीन तो यह में स्लाइड और आगे प्रदर्शित होगा सवाल है, लेकिन मैं चाहता हूं कि जैसे ही वर्तमान प्रश्न स्लाइड हो जाए, इसे अगले प्रश्न के बाद किया जाना चाहिए।

+0

आपने इस एनीमेशन को अपने विचार में कैसे लागू किया? –

+0

हाँ दोस्त मैंने इसे रैखिक लेआउट पर लागू किया है लेकिन क्या होता है कि जब मैं अगले वर्तमान प्रश्न पर क्लिक करता हूं तो बाएं और एक खाली स्क्रीन स्लाइड करेगा, फिर यह स्लाइड करेगा और अगले प्रश्न प्रदर्शित करेगा, लेकिन मैं चाहता हूं कि जैसे ही वर्तमान प्रश्न स्लाइड हो इसके बाद अगले प्रश्न – Goofy

+0

के बाद एक व्यूफ्लिपर का उपयोग करने और इनएनिमेशन और आउट एनीमेशन का उपयोग करने के बारे में क्या होना चाहिए? –

उत्तर

3

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

अब फ्लैग मानों के आधार पर डेटा के साथ उचित विचार लोड करें और showextext() पर कॉल करें।

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mainFlipper = (ViewFlipper) findViewById(R.id.flipper); 
    firstLayout = (LinearLayout) findViewById(R.id.layout1); 
    secondLayout = (LinearLayout) findViewById(R.id.layout2); 


    findViewById(R.id.btnPrevious).setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      showPrevious(); 
     } 
    }); 

    findViewById(R.id.btnNext).setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      showNext(); 
     } 
    }); 

} 

private void showNext() { 
    mainFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_left)); 
    mainFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_right)); 
    flip(); 
} 

private void showPrevious() { 
    mainFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right)); 
    mainFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left)); 
    flip(); 
} 

private void flip() { 
    if(isFirstVisible) { 
     isFirstVisible = false; 
     secondLayout.removeAllViews(); 
     secondLayout.addView(getTextView("Second")); 
    } else { 
     isFirstVisible = true; 
     firstLayout.removeAllViews(); 
     firstLayout.addView(getTextView("First")); 
    } 
    mainFlipper.showNext(); 
} 

private TextView getTextView(String txt) { 
    TextView txtView = new TextView(this); 
    txtView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
    txtView.setText(txt); 
    return txtView; 
} 
+0

धन्यवाद कोशिश करेंगे और आप वापस आ जाएंगे। – Goofy

+0

अरे मैंने जिस तरीके से आपको बताया है, लेकिन अब मैं उस दृश्य को हटाने में सक्षम नहीं हूं जिसे मैं गतिशील रूप से जोड़ रहा हूं, अगर मैं removeallviews() का उपयोग करता हूं तो एनीमेशन काम नहीं करेगा .. – Goofy

+1

मैंने अपनी पोस्ट कोड के साथ संपादित की है। कृपया इसे आजमाएं –

4

में रेस/anim इस xml/

leftright.xml
उपयोग इस के लिए सही एनीमेशन के लिए छोड़ दिया है:

<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <translate android:fromXDelta="-100%" android:toXDelta="0%" 
     android:fromYDelta="0%" android:toYDelta="0%" 
    android:duration="700"/> 
    </set> 

उपयोग यह आपके जावा कोड में

Handler handler = new Handler(); 
Runnable runnable = new Runnable(){ 
{ 
    public void run() 
{ 
    item[i].setInAnimation(AnimationUtils.loadAnimation(this,R.anim.leftright.xml)); 
    i=i+1; 
    handler.postDelayed(this,5000); 
} 
};handler.postDelayed(runnable,5000); 
+0

मैं लेआउट में एनीमेशन कैसे लागू करूं? मैं एनीमेशन को एकल आइटम पर लागू नहीं कर सकता क्योंकि इसे पहले सरणीसूची से मूल्य प्राप्त करना होगा और फिर अगले क्लिक 'setContentView (R.layout पर – Goofy

+0

प्रदर्शित करना होगा।व्यू 2) 'फिर इसे अपनी कक्षा के अंदर करें' इरादा iSecondLayout = नया इरादा (गतिविधि.थिस, गतिविधि.क्लास); Activity.this.startActivity (iSecondLayout); Activity.this.overridePendingTransition (R.anim.lefttightight, R.anim.righttoleft); ' – mjosh

+0

मेरे पास केवल एक गतिविधि है – Goofy

संबंधित मुद्दे