XamarinAndroid组件教程RecylerView动画组件使用动画(3)
XamarinAndroid组件教程RecylerView动画组件使用动画(3)
(8)打开Main.axml文件,构建主界面。代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3DC49D"
android:minHeight="?attr/actionBarSize">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:background="?attr/selectableItemBackground"
android:padding="10dp"
android:text="DEL"/>
<TextView
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/del"
android:layout_centerInParent="true"
android:background="?attr/selectableItemBackground"
android:padding="10dp"
android:text="ADD"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
(9)打开MainActivity.cs文件,设置RecylerView子元素添加和删除时的动画效果。代码如下:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.Widget;
using System.Linq;
using RecyclerViewAnimators.Animators;
using Android.Support.V7.App;
namespace RecylerViewAnimatorsItemAnimator
{
[Activity(Label = "RecylerViewAnimatorsItemAnimator", MainLauncher = true, Icon = "@mipmap/icon", Theme = "@style/AppTheme")]
public class MainActivity : AppCompatActivity
{
static readonly string[] data = {
"Apple", "Ball", "Camera", "Day", "Egg", "Foo", "Google", "Hello", "Iron", "Japan", "Coke",
"Dog", "Cat", "Yahoo", "Sony", "Canon", "Fujitsu", "USA", "Nexus", "LINE", "Haskell", "C++",
"Java", "Go", "Swift", "Objective-c", "Ruby", "PHP", "Bash", "ksh", "C", "Groovy", "Kotlin",
"Chip", "Japan", "U.S.A", "San Francisco", "Paris", "Tokyo", "Silicon Valley", "London",
"Spain", "China", "Taiwan", "Asia", "New York", "France", "Kyoto", "Android", "Google", "C#",
"iPhone", "iPad", "iPod", "Wasabeef", "Xamarin", "South Africa", "Cape Town", "Microsoft"
};
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.tool_bar);
SetSupportActionBar(toolbar);
SupportActionBar.SetDisplayShowTitleEnabled(false);
var recyclerView = FindViewById<RecyclerView>(Resource.Id.list);
recyclerView.SetLayoutManager(new LinearLayoutManager(this)); //设置布局管理
var datalist = data.ToList<string>();
var adapter = new DataAdapter(this, datalist);
recyclerView.SetAdapter(adapter); //设置适配器
recyclerView.SetItemAnimator(new FlipInLeftYAnimator()); //设置动画效果
//添加子元素
FindViewById(Resource.Id.add).Click += (sender, e) => {
adapter.Add("newly added item", 1);
};
//删除子元素
FindViewById(Resource.Id.del).Click += (sender, e) => {
adapter.Remove(1);
};
}
}
}
运行程序后,初始状态如图1.1所示。轻拍Add按钮,实现子元素的添加,在添加子元素的时候会伴有指定动画效果,如图1.2所示。轻拍DEL按钮,实现子元素的删除,在子元素删除的过程中也会伴有指定的动画效果。
图1.1 初始状态 图1.2 添加数据
XamarinAndroid组件教程RecylerView动画组件使用动画(3)的更多相关文章
- XamarinAndroid组件教程RecylerView自定义适配器动画
XamarinAndroid组件教程RecylerView自定义适配器动画 如果RecyclerViewAnimators.Adapters命名空间中没有所需要的适配器动画,开发者可以自定义动画.此时 ...
- XamarinAndroid组件教程RecylerView适配器设置动画示例
XamarinAndroid组件教程RecylerView适配器设置动画示例 [示例1-3]下面将在RecylerView的子元素进行滚动时,使用适配器动画.具体的操作步骤如下: (1)创建一个名为R ...
- XamarinAndroid组件教程RecylerView适配器设置动画
XamarinAndroid组件教程RecylerView适配器设置动画 本小节将讲解动画相关设置,如动画的时长.插值器以及复合动画等. 1.设置动画时长 设置动画持续的时间可以使用Animation ...
- XamarinAndroid组件教程RecylerView适配器使用动画
XamarinAndroid组件教程RecylerView适配器使用动画 为RecylerView使用RecylerViewAnimators组件中提供的适配器动画,需要使用RecyclerView类 ...
- XamarinAndroid组件教程RecylerView适配器动画动画种类
XamarinAndroid组件教程RecylerView适配器动画动画种类 本节将讲解RecylerView适配器动画,其中包含动画种类和如何使用动画. 动画种类 RecylerViewAnimat ...
- XamarinAndroid组件教程RecylerView动画组件使用动画(2)
XamarinAndroid组件教程RecylerView动画组件使用动画(2) 如果开发者要为RecylerView的子元素添加动画效果,需要使用RecyclerView类中的SetItemAnim ...
- XamarinAndroid组件教程设置自定义子元素动画(二)
XamarinAndroid组件教程设置自定义子元素动画(二) (9)打开MainActivity.cs文件,为RecylerView的子元素设置添加和删除时的透明动画效果.代码如下: …… usin ...
- XamarinAndroid组件教程设置自定义子元素动画(一)
XamarinAndroid组件教程设置自定义子元素动画(一) 如果在RecyclerViewAnimators.Animators中没有所需要的动画效果,就可以自定义一个.此时,需要让自定义的动画继 ...
- Xamarin Android组件篇教程RecylerView动画组件RecylerViewAnimators(1)
Xamarin Android组件篇教程RecylerView动画组件RecylerViewAnimators(1) RecyclerView是比ListView和GridView更为强大的布局视图, ...
随机推荐
- Metasploit渗透测试模块(一)
1.Metasploit模块加载 初始化界面,成功要加载数据库 查看 Metasploit中已近存在的漏洞模块使用 show payloads
- light1236 素数打表,质因数分解
不知道为什么会错 /* 求出 lcm(i,j)==n 的对数, 分解质因数,p1^e1 * p2^e2 * p3^e3 那么 i,j中必定有一个数有e1个p1因子,另一个任意即可 那么最终的结果就是 ...
- Git使用一:git客户端安装与创建用户
1.下载并安装Git和图形客户端TortoiseGit Git官网:https://gitforwindows.org/ TortoiseGit官网: https://tortoisegit.org/ ...
- jenkins持续集成:定时构建语法
构建位置:选择或创建工程_设置_构建触发器 1. 定时构建语法:* * * * * (五颗星,多个时间点,中间用逗号隔开)第一个*表示分钟,取值0~59第二个*表示小时,取值0~23第三个*表示一个月 ...
- MySQL架构及SQL语句
MySQL基础: 单进程多线程: 用户连接:连接线程 官方组件架构: MySQL的数据文件类型: 数据文件.索引文件 重做日志.撤销日志.二进制日志.错误日志.查询日志.慢查询日志.中继日志 MySQ ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- 【APUE | 03】文件I/O
博客链接: inux中的文件描述符与打开文件之间的关系 #include <stdio.h> #include <unistd.h> #include <sys/stat ...
- ***在Linux环境下mysql的root密码忘记解决方法(三种)-推荐第三种
MySQL密码的恢复方法之一 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态 ...
- mysql四大特性与四种隔离级别
四大特性 1:原子性.事务是一个不可分割的整体,事务开始的操作,要么全部执行,要么全部不执行. 2:隔离性.同一时间,只允许一个事务请求同一组数据.不同的事务彼此之间没有干扰. 3:一致性.事务开始前 ...
- 使用 curses 函数库管理基于文本的屏幕
curses 函数库提供了终端无关的方式来编写全屏幕的基于字符的程序.curses 还可以管理键盘,提供了一种简单易用的非阻塞字符输入模式. curses 函数库能够优化光标的移动并最小化需要对屏幕进 ...