XamarinAndroid组件教程RecylerView动画组件使用动画(3)

(8)打开Main.axml文件,构建主界面。代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5. android:orientation="vertical"
  6.  
  7. android:layout_width="match_parent"
  8.  
  9. android:layout_height="match_parent">
  10.  
  11. <android.support.v7.widget.Toolbar
  12.  
  13. android:id="@+id/tool_bar"
  14.  
  15. android:layout_width="match_parent"
  16.  
  17. android:layout_height="wrap_content"
  18.  
  19. android:background="#3DC49D"
  20.  
  21. android:minHeight="?attr/actionBarSize">
  22.  
  23. <RelativeLayout
  24.  
  25. android:layout_width="match_parent"
  26.  
  27. android:layout_height="wrap_content">
  28.  
  29. <TextView
  30.  
  31. android:id="@+id/del"
  32.  
  33. android:layout_width="wrap_content"
  34.  
  35. android:layout_height="wrap_content"
  36.  
  37. android:layout_alignParentRight="true"
  38.  
  39. android:layout_centerInParent="true"
  40.  
  41. android:background="?attr/selectableItemBackground"
  42.  
  43. android:padding="10dp"
  44.  
  45. android:text="DEL"/>
  46.  
  47. <TextView
  48.  
  49. android:id="@+id/add"
  50.  
  51. android:layout_width="wrap_content"
  52.  
  53. android:layout_height="wrap_content"
  54.  
  55. android:layout_toLeftOf="@id/del"
  56.  
  57. android:layout_centerInParent="true"
  58.  
  59. android:background="?attr/selectableItemBackground"
  60.  
  61. android:padding="10dp"
  62.  
  63. android:text="ADD"/>
  64.  
  65. </RelativeLayout>
  66.  
  67. </android.support.v7.widget.Toolbar>
  68.  
  69. <android.support.v7.widget.RecyclerView
  70.  
  71. android:id="@+id/list"
  72.  
  73. android:layout_width="match_parent"
  74.  
  75. android:layout_height="match_parent"/>
  76.  
  77. </LinearLayout>

  

(9)打开MainActivity.cs文件,设置RecylerView子元素添加和删除时的动画效果。代码如下:

  1. using Android.App;
  2.  
  3. using Android.Widget;
  4.  
  5. using Android.OS;
  6.  
  7. using Android.Support.V7.Widget;
  8.  
  9. using System.Linq;
  10.  
  11. using RecyclerViewAnimators.Animators;
  12.  
  13. using Android.Support.V7.App;
  14.  
  15. namespace RecylerViewAnimatorsItemAnimator
  16.  
  17. {
  18.  
  19. [Activity(Label = "RecylerViewAnimatorsItemAnimator", MainLauncher = true, Icon = "@mipmap/icon", Theme = "@style/AppTheme")]
  20.  
  21. public class MainActivity : AppCompatActivity
  22.  
  23. {
  24.  
  25. static readonly string[] data = {
  26.  
  27. "Apple", "Ball", "Camera", "Day", "Egg", "Foo", "Google", "Hello", "Iron", "Japan", "Coke",
  28.  
  29. "Dog", "Cat", "Yahoo", "Sony", "Canon", "Fujitsu", "USA", "Nexus", "LINE", "Haskell", "C++",
  30.  
  31. "Java", "Go", "Swift", "Objective-c", "Ruby", "PHP", "Bash", "ksh", "C", "Groovy", "Kotlin",
  32.  
  33. "Chip", "Japan", "U.S.A", "San Francisco", "Paris", "Tokyo", "Silicon Valley", "London",
  34.  
  35. "Spain", "China", "Taiwan", "Asia", "New York", "France", "Kyoto", "Android", "Google", "C#",
  36.  
  37. "iPhone", "iPad", "iPod", "Wasabeef", "Xamarin", "South Africa", "Cape Town", "Microsoft"
  38.  
  39. };
  40.  
  41. protected override void OnCreate(Bundle savedInstanceState)
  42.  
  43. {
  44.  
  45. base.OnCreate(savedInstanceState);
  46.  
  47. SetContentView(Resource.Layout.Main);
  48.  
  49. var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.tool_bar);
  50.  
  51. SetSupportActionBar(toolbar);
  52.  
  53. SupportActionBar.SetDisplayShowTitleEnabled(false);
  54.  
  55. var recyclerView = FindViewById<RecyclerView>(Resource.Id.list);
  56.  
  57. recyclerView.SetLayoutManager(new LinearLayoutManager(this)); //设置布局管理
  58.  
  59. var datalist = data.ToList<string>();
  60.  
  61. var adapter = new DataAdapter(this, datalist);
  62.  
  63. recyclerView.SetAdapter(adapter); //设置适配器
  64.  
  65. recyclerView.SetItemAnimator(new FlipInLeftYAnimator()); //设置动画效果
  66.  
  67. //添加子元素
  68.  
  69. FindViewById(Resource.Id.add).Click += (sender, e) => {
  70.  
  71. adapter.Add("newly added item", 1);
  72.  
  73. };
  74.  
  75. //删除子元素
  76.  
  77. FindViewById(Resource.Id.del).Click += (sender, e) => {
  78.  
  79. adapter.Remove(1);
  80.  
  81. };
  82.  
  83. }
  84.  
  85. }
  86.  
  87. }

  

运行程序后,初始状态如图1.1所示。轻拍Add按钮,实现子元素的添加,在添加子元素的时候会伴有指定动画效果,如图1.2所示。轻拍DEL按钮,实现子元素的删除,在子元素删除的过程中也会伴有指定的动画效果。

图1.1  初始状态                          图1.2  添加数据

XamarinAndroid组件教程RecylerView动画组件使用动画(3)的更多相关文章

  1. XamarinAndroid组件教程RecylerView自定义适配器动画

    XamarinAndroid组件教程RecylerView自定义适配器动画 如果RecyclerViewAnimators.Adapters命名空间中没有所需要的适配器动画,开发者可以自定义动画.此时 ...

  2. XamarinAndroid组件教程RecylerView适配器设置动画示例

    XamarinAndroid组件教程RecylerView适配器设置动画示例 [示例1-3]下面将在RecylerView的子元素进行滚动时,使用适配器动画.具体的操作步骤如下: (1)创建一个名为R ...

  3. XamarinAndroid组件教程RecylerView适配器设置动画

    XamarinAndroid组件教程RecylerView适配器设置动画 本小节将讲解动画相关设置,如动画的时长.插值器以及复合动画等. 1.设置动画时长 设置动画持续的时间可以使用Animation ...

  4. XamarinAndroid组件教程RecylerView适配器使用动画

    XamarinAndroid组件教程RecylerView适配器使用动画 为RecylerView使用RecylerViewAnimators组件中提供的适配器动画,需要使用RecyclerView类 ...

  5. XamarinAndroid组件教程RecylerView适配器动画动画种类

    XamarinAndroid组件教程RecylerView适配器动画动画种类 本节将讲解RecylerView适配器动画,其中包含动画种类和如何使用动画. 动画种类 RecylerViewAnimat ...

  6. XamarinAndroid组件教程RecylerView动画组件使用动画(2)

    XamarinAndroid组件教程RecylerView动画组件使用动画(2) 如果开发者要为RecylerView的子元素添加动画效果,需要使用RecyclerView类中的SetItemAnim ...

  7. XamarinAndroid组件教程设置自定义子元素动画(二)

    XamarinAndroid组件教程设置自定义子元素动画(二) (9)打开MainActivity.cs文件,为RecylerView的子元素设置添加和删除时的透明动画效果.代码如下: …… usin ...

  8. XamarinAndroid组件教程设置自定义子元素动画(一)

    XamarinAndroid组件教程设置自定义子元素动画(一) 如果在RecyclerViewAnimators.Animators中没有所需要的动画效果,就可以自定义一个.此时,需要让自定义的动画继 ...

  9. Xamarin Android组件篇教程RecylerView动画组件RecylerViewAnimators(1)

    Xamarin Android组件篇教程RecylerView动画组件RecylerViewAnimators(1) RecyclerView是比ListView和GridView更为强大的布局视图, ...

随机推荐

  1. laravel 里面结合关联查询 的when()用法

    Laravel 5.6 里面的when用法: $name = $request->get('name'); //活动标题 $start_time = $request->get('star ...

  2. django----图书管理

    待完成 from django.db import models # Create your models here. class Book(models.Model): nid = models.A ...

  3. MySQL5.7.20报错Access denied for user 'root'@'localhost' (using password: NO)

    在centos6.8上源码安装了MySQL5.7.20,进入mysql的时候报错如下: 解决办法如下: 在mysql的配置文件内加入: vim  /etc/my.cnf skip-grant-tabl ...

  4. spring cloud feign覆写默认配置级feign client的日志打印

    一.覆写fegin的默认配置 1.新增配置类FeignConfiguration.java package com.config; import org.springframework.context ...

  5. asp.net core 缓存和Session

    缓存 缓存在内存中 ASP.NET Core 使用 IMemoryCache内存中缓存是使用依赖关系注入从应用中引用的服务. 请在ConfigureServices中调用AddMemoryCache( ...

  6. dnsjava usage

    linux dig 命令使用方法 https://www.imooc.com/article/26971?block_id=tuijian_wz https://jimwayne.blogspot.c ...

  7. 18/03/18 04:53:44 WARN TaskSchedulerImpl: Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources

    1:遇到这个问题是在启动bin/spark-shell以后,然后呢,执行spark实现wordcount的例子的时候出现错误了,如: scala> sc.textFile()).reduceBy ...

  8. java.net.UnknownHostException: master

    1:如果你报这个错误,第一反应应该是本地的host文件没有配置服务器名称和对应的ip地址,这个反应就对了.贴一下错误和解决方法: java.net.UnknownHostException: mast ...

  9. python爬虫实例

    import re import requests from bs4 import BeautifulSoup # 主方法 def main(): # 给请求指定一个请求头来模拟chrome浏览器 h ...

  10. 清北合肥day1

    题目: 1.给出一个由0,1组成的环 求最少多少次交换(任意两个位置)使得0,1靠在一起 n<=1000 2.两个数列,支持在第一个数列上区间+1,-1 每次花费为1 求a变成b的最小代价 n& ...