In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use animation in XamarinAndroid RecylerView animation components, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
If the developer wants to add animation to the child elements of RecylerView, you need to use the SetItemAnimator () method in the RecyclerView class, which has the following syntax:
Public virtual void SetItemAnimator (Android.Support.V7.Widget.RecyclerView.ItemAnimator animator)
Where the animator parameter specifies an animation, which is the type of animation listed in Table 1-1.
[example 1-1] the following will animate child elements when adding and deleting child elements of RecylerView. The specific steps are as follows:
(1) create a project called RecylerViewAnimatorsItemAnimator
(2) RecyclerViewAnimators.dll, Square.OkHttp.dll, Square.OkIO.dll, Square.Picasso.dll, Xamarin.Android.Arch.Core.Common.dll, Xamarin.Android.Arch.Lifecycle.Common.dll, Xamarin.Android.Arch.Lifecycle.Runtime.dll, Xamarin.Android.Support.Animated.Vector.Drawable.dll, Xamarin.Android.Support.Annotations.dll, Xamarin.Android.Support.Compat.dll, Xamarin.Android.Support.Core.UI.dll, Xamarin.Android.Support.Core.Utils.dll, Xamarin.Android.Support.Fragment.dll, The Xamarin.Android.Support.Media.Compat.dll, Xamarin.Android.Support.v4.dll, Xamarin.Android.Support.v7.AppCompat.dll, Xamarin.Android.Support.v7.RecyclerView.dll, and Xamarin.Android.Support.Vector.Drawable.dll libraries are added to the reference to the RecylerViewAnimatorsItemAnimator project.
(3) add the picture image.jpg to the drawable folder under Resources of the RecylerViewAnimatorsItemAnimator project.
(4) create a xml file named layout_list_item.
(5) Open the layout_list_item.cs file and build the child elements of RecylerView. The code is as follows:
(6) create an adapter file named DataAdapter.
(7) Open the DataAdapter.cs file and add the following code:
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Text
Using Android.App
Using Android.Content
Using Android.OS
Using Android.Runtime
Using Android.Views
Using Android.Widget
Using Square.Picasso
Using Android.Support.V7.Widget
Namespace RecylerViewAnimatorsItemAnimator
{
Public class DataAdapter: RecyclerView.Adapter
{
Context context
List dataset
/ / Construction method
Public DataAdapter (Context context, List dataset)
{
This.context = context
This.dataset = dataset
}
/ / number of child elements
Public override int ItemCount
{
Get
{
Return dataset.Count
}
}
/ / return a custom ViewHolder
Public override RecyclerView.ViewHolder OnCreateViewHolder (ViewGroup parent, int viewType)
{
Var v = LayoutInflater.From (context) .Inflate (Resource.Layout.layout_list_item, parent, false)
Return new ViewHolder (v)
}
/ / populate the controls in the ViewHolder returned by the onCreateViewHolder () method
Public override void OnBindViewHolder (RecyclerView.ViewHolder holder, int position)
{
Var h = (ViewHolder) holder
Picasso.With (context) .load (Resource.Drawable.image) .into (h.Image)
H.Text.Text = dataset [position]
}
/ / Delete child elements
Public void Remove (int position)
{
Dataset.RemoveAt (position)
NotifyItemRemoved (position)
}
/ / add child elements
Public void Add (string text, int position)
{
Dataset.Insert (position, text)
NotifyItemInserted (position)
}
Private class ViewHolder: RecyclerView.ViewHolder
{
Public ImageView Image {get; private set;}
Public TextView Text {get; private set;}
Public ViewHolder (View itemView)
: base (itemView)
{
Image = itemView.FindViewById (Resource.Id.image)
Text = itemView.FindViewById (Resource.Id.text)
}
}
}
}
Note: developers can trigger child element animations only if they call the NotifyItemRemoved (), NotifyItemInserted (), NotifyItemChanged (), and NotifyItemMoved () methods.
These are all the contents of the article "how to use Animation in RecylerView Animation components in XamarinAndroid". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.