বাংলায় অ্যান্ড্রয়েড সহায়িকা - Bangla Android Guide

কার্ড ফ্লিপ অ্যানিমেট করা

এখন আপনার একটি প্যারেন্ট একটিভিটির মধ্যে ফ্রাগমেন্ট প্রদর্শন করার প্রয়োজন্ এটা করতে, প্রথমে আপনার একটিভিটির জন্য লেআউট তৈরী করুন। নীচের উদাহরন একটি FrameLayout করেছে যাতে আপনি ফ্রাগমেন্ট রানটাইমের সময় এতে এটা সেট করতে পারবেন:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

একটিভিটি কোডে, লেআউট হতে কনটেন্ট ভিউ সেট করুন যা আপনি মাত্র তৈরী করেছেন। একটি ডিফল্ট ফ্রাগমেন্ট দেখানো একটি ভালো চিন্তা যখন একটিভিটি তৈরী হয়, সুতরাং নিম্নোক্ত উদাহরন একটিভিটি আপনাকে দেখায় বাই ডিফল্ট কীভাবে কার্ডের সম্মূখভাগ প্রদর্শন করতে হয়:

public class CardFlipActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_card_flip);

        if (savedInstanceState == null) {
            getFragmentManager()
                    .beginTransaction()
                    .add(R.id.container, new CardFrontFragment())
                    .commit();
        }
    }
    ...
}

এখন আপনার সম্মূখভাগ প্রদর্শন করার ব্যবস্থা আছে, আপনি একটি যথাযথ সময়ে ফ্লিপ অ্যানিমেশন দিয়ে কার্ডেও পেছনভাগ প্রদর্শন করতে পারেন। কার্ডের অন্য পার্শ্ব প্রদর্শন করতে একটি পদ্ধতি তৈরী করুন যা নিম্নোক্ত বিষয়গুলো সম্পাদন করে:

  • কাস্টম অ্যানিমেশন সেট করুন যা ফ্রাগমেন্ট পরিবর্তন করার জন্য আপনি ইতিপূর্বে তৈরী করেছেন।

  • একটি নতুন ফ্রাগমেন্টর সাথে বর্তমানে প্রদর্শিত ফ্রাগমেন্টেকে প্রতিস্থাপন করুন এবং কাস্টম অ্যানিমেশন যা আপনি তৈরী করেছেন তা দিয়ে এই ইভেন্ট অ্যানিমেট করুন।

  • ফ্রাগমেন্ট ব্যাক স্টেকে পূর্বে প্রদর্শিত ফ্রাগমেন্ট যুক্ত করুন তাই যখন ইউজার বাক বাটন প্রেস করবে, কার্ড ফ্লিপ করে টেছনে চলে যাবে।

    private void flipCard() {

      if (mShowingBack) {
          getFragmentManager().popBackStack();
          return;
      }
    
      // Flip to the back.
    
      mShowingBack = true;
    
      // Create and commit a new fragment transaction that adds the fragment for the back of
      // the card, uses custom animations, and is part of the fragment manager's back stack.
    
      getFragmentManager()
              .beginTransaction()
    
              // Replace the default fragment animations with animator resources representing
              // rotations when switching to the back of the card, as well as animator
              // resources representing rotations when flipping back to the front (e.g. when
              // the system Back button is pressed).
              .setCustomAnimations(
                      R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                      R.animator.card_flip_left_in, R.animator.card_flip_left_out)
    
              // Replace any fragments currently in the container view with a fragment
              // representing the next page (indicated by the just-incremented currentPage
              // variable).
              .replace(R.id.container, new CardBackFragment())
    
              // Add this transaction to the back stack, allowing users to press Back
              // to get to the front of the card.
              .addToBackStack(null)
    
              // Commit the transaction.
              .commit();
    

    }