আপনার অ্যাপ ব্যবহার করার সময়, স্ক্রিনে নতুন তথ্য দেখানো হয় এবং পুরনো তথ্য সরিয়ে দেওয়া হয়। স্ক্রিনে যা দেখানো হচ্ছে তা অবিলম্বে পরিবর্তন করা হলে তা বিরক্তিকর হতে পারে এবং ব্যবহারকারীরা হঠাৎ দেখানো নতুন কন্টেন্ট মিস করতে পারেন। অ্যানিমেশন পরিবর্তনগুলিকে ধীর করে দেয় এবং মোশনের মাধ্যমে ব্যবহারকারীর দৃষ্টি আকর্ষণ করে যাতে আপডেটগুলি আরও স্পষ্ট হয়।
কোনও ভিউ দেখাতে বা লুকাতে আপনি তিনটি সাধারণ অ্যানিমেশন ব্যবহার করতে পারেন: রিভিল অ্যানিমেশন, ক্রসফেড অ্যানিমেশন এবং কার্ডফ্লিপ অ্যানিমেশন।
ক্রসফেড অ্যানিমেশন তৈরি করুন
ক্রসফেড অ্যানিমেশন—যা ডিসলভ নামেও পরিচিত—ধীরে ধীরে একটি View বা ViewGroup ফেড আউট করে এবং একই সাথে অন্য একটি ফেড ইন করে। এই অ্যানিমেশনটি এমন পরিস্থিতিতে উপযোগী যেখানে আপনি
আপনার অ্যাপে কন্টেন্ট বা ভিউ পরিবর্তন করতে চান। এখানে দেখানো ক্রসফেড অ্যানিমেশন
ViewPropertyAnimator ব্যবহার করে,
যা Android 3.1 (API লেভেল 12) এবং তার পরবর্তী ভার্সনের জন্য উপলভ্য।
প্রোগ্রেস ইন্ডিকেটর থেকে টেক্সট কন্টেন্টে ক্রসফেডের একটি উদাহরণ এখানে দেওয়া হল:
ভিউ তৈরি করুন
আপনি ক্রসফেড করতে চান এমন দুটি ভিউ তৈরি করুন। নিম্নলিখিত উদাহরণটি একটি প্রোগ্রেস ইন্ডিকেটর এবং একটি স্ক্রোলযোগ্য টেক্সট ভিউ তৈরি করে:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView style="?android:textAppearanceMedium"
android:lineSpacingMultiplier="1.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/lorem_ipsum"
android:padding="16dp" />
</ScrollView>
<ProgressBar android:id="@+id/loading_spinner"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
ক্রসফেড অ্যানিমেশন সেট-আপ করুন
ক্রসফেড অ্যানিমেশন সেট-আপ করতে, নিম্নলিখিত ধাপগুলি অনুসরণ করুন:
- আপনি যে ভিউ ক্রসফেড করতে চান সেটির জন্য মেম্বার ভেরিয়েবল তৈরি করুন। অ্যানিমেশন চলাকালীন ভিউ পরিবর্তন করার সময় আপনার এই রেফারেন্সগুলি প্রয়োজন হবে।
- যে ভিউ ফেড-ইন করা হচ্ছে তার দৃশ্যমানতা
GONE-এ সেট করুন। এটি ভিউকে লেআউট স্পেস ব্যবহার করা থেকে আটকায় এবং লেআউট গণনা থেকে বাদ দেয়, যা প্রসেসিংয়ের গতি বাড়ায় - মেম্বার ভেরিয়েবেলে
config_shortAnimTimeসিস্টেম প্রপার্টি ক্যাশে করুন। এই প্রপার্টি অ্যানিমেশনের জন্য স্ট্যান্ডার্ড "ছোট" সময়কাল নির্ধারণ করে। এই সময়কাল সূক্ষ্ম অ্যানিমেশন বা ঘন ঘন ঘটে এমন অ্যানিমেশনের জন্য আদর্শ। এছাড়াও,config_longAnimTimeএবংconfig_mediumAnimTimeউপলভ্য।
অ্যাক্টিভিটি কন্টেন্ট ভিউ হিসেবে আগের কোড স্নিপেট থেকে লেআউট ব্যবহার করার একটি উদাহরণ এখানে দেওয়া হল:
Kotlin
class CrossfadeActivity : Activity() { private lateinit var contentView: View private lateinit var loadingView: View private var shortAnimationDuration: Int = 0 ... override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_crossfade) contentView = findViewById(R.id.content) loadingView = findViewById(R.id.loading_spinner) // Initially hide the content view. contentView.visibility = View.GONE // Retrieve and cache the system's default "short" animation time. shortAnimationDuration = resources.getInteger(android.R.integer.config_shortAnimTime) } ... }
জাভা
public class CrossfadeActivity extends Activity { private View contentView; private View loadingView; private int shortAnimationDuration; ... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_crossfade); contentView = findViewById(R.id.content); loadingView = findViewById(R.id.loading_spinner); // Initially hide the content view. contentView.setVisibility(View.GONE); // Retrieve and cache the system's default "short" animation time. shortAnimationDuration = getResources().getInteger( android.R.integer.config_shortAnimTime); } ... }
ভিউ ক্রসফেড করুন
ভিউ সঠিকভাবে সেট-আপ করা হয়ে গেলে, নিম্নলিখিত ধাপগুলি অনুসরণ করে ক্রসফেড করুন:
- যে ভিউ ফেড-ইন হচ্ছে, সেটির আলফা ভ্যালু ০ এবং দৃশ্যমানতা
GONE-এর প্রাথমিক সেটিং থেকেVISIBLE-এ সেট করুন। এটি ভিউকে দৃশ্যমান কিন্তু স্বচ্ছ করে তোলে। - যে ভিউ ফেড-ইন হচ্ছে, সেটির আলফা ভ্যালু ০ থেকে ১ পর্যন্ত অ্যানিমেট করুন। যে ভিউ ফেড আউট হচ্ছে, সেটির আলফা ভ্যালু ১ থেকে ০-তে অ্যানিমেট করুন।
Animator.AnimatorListener-এonAnimationEnd()ব্যবহার করে, যে ভিউ ফেড আউট হচ্ছে সেটির দৃশ্যমানতাGONE-এ সেট করুন। আলফা ভ্যালু 0 হলেও, ভিউয়ের দৃশ্যমানতাGONE-এ সেট করলে, ভিউ লেআউট স্পেস ব্যবহার করতে পারে না এবং লেআউট গণনা থেকে এটি বাদ যায়, যার ফলে প্রসেসিংয়ের গতি বৃদ্ধি পায়।
এটি কীভাবে করতে হয় তার উদাহরণ নিম্নলিখিত পদ্ধতিতে দেখানো হয়েছে:
Kotlin
class CrossfadeActivity : Activity() { private lateinit var contentView: View private lateinit var loadingView: View private var shortAnimationDuration: Int = 0 ... private fun crossfade() { contentView.apply { // Set the content view to 0% opacity but visible, so that it is // visible but fully transparent during the animation. alpha = 0f visibility = View.VISIBLE // Animate the content view to 100% opacity and clear any animation // listener set on the view. animate() .alpha(1f) .setDuration(shortAnimationDuration.toLong()) .setListener(null) } // Animate the loading view to 0% opacity. After the animation ends, // set its visibility to GONE as an optimization step so it doesn't // participate in layout passes. loadingView.animate() .alpha(0f) .setDuration(shortAnimationDuration.toLong()) .setListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator) { loadingView.visibility = View.GONE } }) } }
জাভা
public class CrossfadeActivity extends Activity { private View contentView; private View loadingView; private int shortAnimationDuration; ... private void crossfade() { // Set the content view to 0% opacity but visible, so that it is // visible but fully transparent during the animation. contentView.setAlpha(0f); contentView.setVisibility(View.VISIBLE); // Animate the content view to 100% opacity and clear any animation // listener set on the view. contentView.animate() .alpha(1f) .setDuration(shortAnimationDuration) .setListener(null); // Animate the loading view to 0% opacity. After the animation ends, // set its visibility to GONE as an optimization step so it doesn't // participate in layout passes. loadingView.animate() .alpha(0f) .setDuration(shortAnimationDuration) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { loadingView.setVisibility(View.GONE); } }); } }
কার্ড ফ্লিপ অ্যানিমেশন তৈরি করুন
কার্ড ফ্লিপ, কন্টেন্টের ভিউয়ের মধ্যে পরিবর্তন করে। এটি করার জন্য কার্ড ফ্লিপ করার মতো
অ্যানিমেশন দেখানো হয়। এখানে দেখানো কার্ড ফ্লিপ অ্যানিমেশন
FragmentTransaction ব্যবহার করে।
কার্ড ফ্লিপ করলে কেমন দেখায় তা এখানে দেওয়া হল:
অ্যানিমেটর অবজেক্ট তৈরি করুন
কার্ড ফ্লিপ অ্যানিমেশন তৈরি করতে, আপনার চারজন অ্যানিমেটর প্রয়োজন। কার্ডের সামনের অংশ অ্যানিমেট হয়ে বেরিয়ে যাওয়ার সময় এবং বাঁদিকে যাওয়ার সময় এবং এটি অ্যানিমেট হয়ে ভিতরে আসার সময় এবং বাঁদিক থেকে আসার সময়ের জন্য দুটি অ্যানিমেটর আছে। অন্য দুটি অ্যানিমেটর হল কার্ডের পিছনের অংশ ডানদিক থেকে অ্যানিমেট করে ভিতরে আসার জন্য এবং ডানদিকে অ্যানিমেট করে বাইরে যাওয়ার জন্য।
card_flip_left_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<!-- Rotate. -->
<objectAnimator
android:valueFrom="-180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Halfway through the rotation, set the alpha to 1. See startOffset. -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>
card_flip_left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Rotate. -->
<objectAnimator
android:valueFrom="0"
android:valueTo="180"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Halfway through the rotation, set the alpha to 0. See startOffset. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>
card_flip_right_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<!-- Rotate. -->
<objectAnimator
android:valueFrom="180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Halfway through the rotation, set the alpha to 1. See startOffset. -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>
card_flip_right_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Rotate. -->
<objectAnimator
android:valueFrom="0"
android:valueTo="-180"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Halfway through the rotation, set the alpha to 0. See startOffset. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>
ভিউ তৈরি করুন
কার্ডের প্রতিটি দিক হল একটি আলাদা লেআউট যাতে আপনার পছন্দমতো যেকোনও কন্টেন্ট থাকতে পারে, যেমন দুটি টেক্সট ভিউ, দুটি ছবি বা ফ্লিপ করার জন্য ভিউয়ের যেকোনও কম্বিনেশন। ফ্র্যাগমেন্টে দুটি লেআউট ব্যবহার করুন যা আপনি পরে অ্যানিমেট করবেন। নিম্নলিখিত লে-আউট কার্ডের একদিক তৈরি করে, যেখানে টেক্সট দেখানো হয়:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#a6c"
android:padding="16dp"
android:gravity="bottom">
<TextView android:id="@android:id/text1"
style="?android:textAppearanceLarge"
android:textStyle="bold"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/card_back_title" />
<TextView style="?android:textAppearanceSmall"
android:textAllCaps="true"
android:textColor="#80ffffff"
android:textStyle="bold"
android:lineSpacingMultiplier="1.2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/card_back_description" />
</LinearLayout>
এবং পরবর্তী লেআউট কার্ডের অন্য দিকটি তৈরি করে, যা একটি
ImageView দেখায়:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image1"
android:scaleType="centerCrop"
android:contentDescription="@string/description_image_1" />
ফ্র্যাগমেন্ট তৈরি করুন
কার্ডের সামনের ও পিছনের দিকের জন্য ফ্র্যাগমেন্ট ক্লাস তৈরি করুন। আপনার ফ্র্যাগমেন্ট
ক্লাসে, onCreateView()
পদ্ধতি থেকে আপনার তৈরি করা লেআউট ফিরিয়ে দিন। আপনি যেখানে কার্ড দেখাতে চান সেখানে প্যারেন্ট অ্যাক্টিভিটিতে
এই ফ্র্যাগমেন্টের ইনস্ট্যান্স তৈরি করতে পারবেন।
নিচের উদাহরণে পেরেন্ট অ্যাক্টিভিটির মধ্যে নেস্টেড ফ্র্যাগমেন্ট ক্লাস দেখানো হয়েছে যা এগুলি ব্যবহার করে:
Kotlin
class CardFlipActivity : FragmentActivity() { ... /** * A fragment representing the front of the card. */ class CardFrontFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View = inflater.inflate(R.layout.fragment_card_front, container, false) } /** * A fragment representing the back of the card. */ class CardBackFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View = inflater.inflate(R.layout.fragment_card_back, container, false) } }
জাভা
public class CardFlipActivity extends FragmentActivity { ... /** * A fragment representing the front of the card. */ public class CardFrontFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_card_front, container, false); } } /** * A fragment representing the back of the card. */ public class CardBackFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_card_back, container, false); } } }
কার্ড ফ্লিপ অ্যানিমেট করুন
পেরেন্ট অ্যাক্টিভিটির মধ্যে ফ্র্যাগমেন্ট দেখান। এটি করতে, আপনার অ্যাক্টিভিটির জন্য
লেআউট তৈরি করুন। নিম্নলিখিত উদাহরণটি একটি
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" />
অ্যাক্টিভিটি কোডে, আপনার তৈরি করা লেআউট অনুযায়ী কন্টেন্ট ভিউ সেট করুন। অ্যাক্টিভিটি তৈরি করার সময় ডিফল্ট ফ্র্যাগমেন্ট দেখানো একটি ভালো অভ্যাস। নিম্নলিখিত উদাহরণ অ্যাক্টিভিটি থেকে বোঝা যায় যে কীভাবে ডিফল্ট হিসেবে কার্ডের সামনের দিক দেখানো হয়:
Kotlin
class CardFlipActivity : FragmentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_activity_card_flip) if (savedInstanceState == null) { supportFragmentManager.beginTransaction() .add(R.id.container, CardFrontFragment()) .commit() } } ... }
জাভা
public class CardFlipActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity_card_flip); if (savedInstanceState == null) { getSupportFragmentManager() .beginTransaction() .add(R.id.container, new CardFrontFragment()) .commit(); } } ... }
কার্ডের সামনের দিকটি দেখানোর সাথে সাথে, আপনি উপযুক্ত সময়ে ফ্লিপ অ্যানিমেশনের মাধ্যমে কার্ডের পিছনের দিকটি দেখাতে পারেন। কার্ডের অন্য দিক দেখানোর জন্য একটি পদ্ধতি তৈরি করো যা নিম্নলিখিত কাজগুলি করে:
- ফ্র্যাগমেন্ট ট্রানজিশনের জন্য আপনার তৈরি করা কাস্টম অ্যানিমেশন সেট করে।
- নতুন ফ্র্যাগমেন্টের সাথে দেখানো ফ্র্যাগমেন্ট পরিবর্তন করে এবং আপনার তৈরি করা কাস্টম অ্যানিমেশনের সাথে এই ইভেন্ট অ্যানিমেট করে।
- আগে দেখানো ফ্র্যাগমেন্টকে ফ্র্যাগমেন্ট ব্যাক স্ট্যাকে যোগ করে, যাতে ব্যবহারকারী 'ফিরে যান' বোতামে ট্যাপ করলে, কার্ডটি আবার ফ্লিপ করে।
Kotlin
class CardFlipActivity : FragmentActivity() { ... private fun flipCard() { if (showingBack) { supportFragmentManager.popBackStack() return } // Flip to the back. showingBack = 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. supportFragmentManager.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, such as when the // system Back button is tapped. .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 in the container view with a fragment // representing the next page, indicated by the just-incremented // currentPage variable. .replace(R.id.container, CardBackFragment()) // Add this transaction to the back stack, letting users press // the Back button to get to the front of the card. .addToBackStack(null) // Commit the transaction. .commit() } }
জাভা
public class CardFlipActivity extends FragmentActivity { ... private void flipCard() { if (showingBack) { getSupportFragmentManager().popBackStack(); return; } // Flip to the back. showingBack = 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. getSupportFragmentManager() .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, such as 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 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, letting users press // Back to get to the front of the card. .addToBackStack(null) // Commit the transaction. .commit(); } }
একটি বৃত্তাকার রিভিল অ্যানিমেশন তৈরি করুন
রিভিল অ্যানিমেশন ব্যবহারকারীদের ভিজ্যুয়াল কন্টিনিউটি প্রদান করে যখন আপনি UI এলিমেন্টের গ্রুপ
দেখান বা লুকান। ViewAnimationUtils.createCircularReveal()
পদ্ধতি আপনাকে একটি ভিউ প্রকাশ বা লুকানোর জন্য একটি ক্লিপিং সার্কেল অ্যানিমেট করতে দেয়। এই
অ্যানিমেশনটি
ViewAnimationUtils ক্লাসে প্রদান করা হয়,
যা Android 5.0 (API লেভেল ২১) এবং তার পরবর্তী যেকোনও ভার্সনের জন্য উপলভ্য।
আগে দেখা যায়নি এমন ভিউ কীভাবে প্রকাশ করতে হয় তার উদাহরণ এখানে দেওয়া হল:
Kotlin
// A previously invisible view. val myView: View = findViewById(R.id.my_view) // Check whether the runtime version is at least Android 5.0. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Get the center for the clipping circle. val cx = myView.width / 2 val cy = myView.height / 2 // Get the final radius for the clipping circle. val finalRadius = Math.hypot(cx.toDouble(), cy.toDouble()).toFloat() // Create the animator for this view. The start radius is 0. val anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0f, finalRadius) // Make the view visible and start the animation. myView.visibility = View.VISIBLE anim.start() } else { // Set the view to invisible without a circular reveal animation below // Android 5.0. myView.visibility = View.INVISIBLE }
জাভা
// A previously invisible view. View myView = findViewById(R.id.my_view); // Check whether the runtime version is at least Android 5.0. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Get the center for the clipping circle. int cx = myView.getWidth() / 2; int cy = myView.getHeight() / 2; // Get the final radius for the clipping circle. float finalRadius = (float) Math.hypot(cx, cy); // Create the animator for this view. The start radius is 0. Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0f, finalRadius); // Make the view visible and start the animation. myView.setVisibility(View.VISIBLE); anim.start(); } else { // Set the view to invisible without a circular reveal animation below // Android 5.0. myView.setVisibility(View.INVISIBLE); }
ViewAnimationUtils.createCircularReveal() অ্যানিমেশনে পাঁচটি প্যারামিটার আছে।
প্রথম প্যারামিটার হল সেই ভিউ যা আপনি স্ক্রিনে লুকাতে বা দেখাতে চান। পরবর্তী
দুটি প্যারামিটার হল ক্লিপিং বৃত্তের কেন্দ্রের X এবং Y স্থানাঙ্ক। সাধারণত, এটি ভিউয়ের কেন্দ্রবিন্দু, তবে আপনি ব্যবহারকারীর ট্যাপ করা পয়েন্টও ব্যবহার করতে পারেন যাতে তারা যেখানে বেছে নেয় সেখান থেকে অ্যানিমেশন শুরু হয়। চতুর্থ প্যারামিটারটি হল ক্লিপিং সার্কেলের শুরুর ব্যাসার্ধ।
আগের উদাহরণে, প্রাথমিক ব্যাসার্ধ শূন্যতে সেট করা হয়েছে যাতে বৃত্তের মাধ্যমে দেখানো ভিউ লুকানো যায়। শেষ প্যারামিটারটি হল বৃত্তের চূড়ান্ত ব্যাসার্ধ। কোনও ভিউ দেখানোর সময়, চূড়ান্ত ব্যাসার্ধ ভিউয়ের চেয়ে বড় করুন যাতে অ্যানিমেশন শেষ হওয়ার আগে ভিউটি সম্পূর্ণভাবে প্রকাশ করা যায়।
আগে দেখা যাচ্ছিল এমন ভিউ লুকাতে, নিম্নলিখিত ধাপগুলি অনুসরণ করুন:
Kotlin
// A previously visible view. val myView: View = findViewById(R.id.my_view) // Check whether the runtime version is at least Android 5.0. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Get the center for the clipping circle. val cx = myView.width / 2 val cy = myView.height / 2 // Get the initial radius for the clipping circle. val initialRadius = Math.hypot(cx.toDouble(), cy.toDouble()).toFloat() // Create the animation. The final radius is 0. val anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0f) // Make the view invisible when the animation is done. anim.addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator) { super.onAnimationEnd(animation) myView.visibility = View.INVISIBLE } }) // Start the animation. anim.start() } else { // Set the view to visible without a circular reveal animation below // Android 5.0. myView.visibility = View.VISIBLE }
জাভা
// A previously visible view. final View myView = findViewById(R.id.my_view); // Check whether the runtime version is at least Android 5.0. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Get the center for the clipping circle. int cx = myView.getWidth() / 2; int cy = myView.getHeight() / 2; // Get the initial radius for the clipping circle. float initialRadius = (float) Math.hypot(cx, cy); // Create the animation. The final radius is 0. Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0f); // Make the view invisible when the animation is done. anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); myView.setVisibility(View.INVISIBLE); } }); // Start the animation. anim.start(); } else { // Set the view to visible without a circular reveal animation below Android // 5.0. myView.setVisibility(View.VISIBLE); }
এই ক্ষেত্রে, ক্লিপিং সার্কেলের প্রাথমিক ব্যাসার্ধ ভিউয়ের মতো বড় করে সেট করা হয়
যাতে অ্যানিমেশন শুরু হওয়ার আগে ভিউ দেখা যায়। চূড়ান্ত
ব্যাসার্ধ শূন্যে সেট করা হয় যাতে অ্যানিমেশন শেষ হলে ভিউটি লুকানো থাকে।
অ্যানিমেশনে একজন শ্রোতা যোগ করুন যাতে অ্যানিমেশন সম্পূর্ণ হলে ভিউয়ের দৃশ্যমানতা
INVISIBLE-এ সেট করা যায়।
অতিরিক্ত রিসোর্স
- Jetpack Compose-এর মাধ্যমে অ্যানিমেশন।
- Jetpack Compose-এর সাথে জেসচার।