AndroidUI 布局动画-为列表添加布局动画效果
新建一个Android project ,使MainActivity 继承自 ListActivity;
public class MainActivity extends ListActivity {
private ArrayAdapter<String> aa;
private LayoutAnimationController la;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
aa=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_activated_1
, new String[]{"Jack","Tom","Mali","kelusi"});
setListAdapter(aa);
ScaleAnimation scale=new ScaleAnimation(0,1,0,1);
scale.setDuration(1000);
la=new LayoutAnimationController(scale, 0.5f);
getListView().setLayoutAnimation(la);
}
}
效果:
为了使代码看起来更加简洁,我们使用XML配置ListView的动画效果,新建一个缩放动画效果res/anim/listview_scale.xml:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0" android:toXScale="1"
android:fromYScale="0" android:toYScale="1"
android:duration="1000"> </scale>
新建一个LayoutAnimation,res/anim/listview_anim.xml(虽然layoutAnimation没有智能提示,但一样可以使用):
让LayoutAnimation的Animation=listview_scale.xml
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/listview_scale"
android:delay="0.5">
</layoutAnimation>
新建一个布局文件 main.xml,在布局 文件内添加一个ListView ,将LayoutAnimation效果 添加到ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" > <ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/listview_anim">
</ListView>
</LinearLayout>
在这里需要特别注意,ListView的ID必须等 于
@android:id/list
后台代码就很简单 了,加载Main.xml即可
public class MainActivity extends ListActivity {
private ArrayAdapter<String> aa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aa=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_activated_1
, new String[]{"Jack","Tom","Mali","kelusi"});
setListAdapter(aa);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
AndroidUI 布局动画-为列表添加布局动画效果的更多相关文章
- jQuery停止动画和判断是否处于动画状态
1.停止元素的动画 stop([clearQueue][,gotoEnd]); 参数clearQHCHC和gotoEnd都足町选的参数,为Boolean值(ture或flase).clearQueue ...
- Android动画效果之自定义ViewGroup添加布局动画
前言: 前面几篇文章介绍了补间动画.逐帧动画.属性动画,大部分都是针对View来实现的动画,那么该如何为了一个ViewGroup添加动画呢?今天结合自定义ViewGroup来学习一下布局动画.本文将通 ...
- 自定义ViewGroup添加布局动画
声明几个属性值: <declare-styleable name="GridImageViewGroup"> <attr name="childVert ...
- CCS3的过渡、变换、动画以及响应式布局、弹性布局
CSS3 过渡 .变换.动画 在没有CSS3之前,如果页面上需要一些动画效果,要么你自己编写 JavaScript,要么使用 JavaScript 框架(如 jQuery)来提高效率. 但是CSS3出 ...
- css盒子布局,浮动布局以及显影与简单的动画
08.05自我总结 一.盒子布局 1.盒子布局的组成 margin border padding content 2.margin margin是外边距,控制盒子的显示位置相对于他的上一级 left. ...
- ListView在列表的头部和底部添加布局——addHeaderView,addFooterView
addHeaderView()方法:主要是向listView的头部添加布局addFooterView()方法:主要是向listView的底部添加布局 以addHeaderView为例: View he ...
- Android使用shape制作圆形控件及添加弹跳动画
--------本来为作者原创,未经同意禁止转载 前言:我们在很多时候都需要在res/drawable文件夹下创建相应的xml文件来为控件添加一些样式效果,比如按钮按下时的按钮样式变化.或者指定按钮的 ...
- Android为ViewPager添加切换动画——自己定义ViewPager
转载请注明出处:http://blog.csdn.net/allen315410/article/details/44224517 在上篇博客中,我写了一个使用属性动画为ViewPager加入切换动画 ...
- 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现
写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...
随机推荐
- Node.js HTTP 使用详解
对于初学者有没有发觉在查看Node.js官方API的时候非常简单,只有几个洋文描述两下子,没了,我第一次一口气看完所以API后,对于第一个示例都有些懵,特别是参数里的request和response, ...
- delphi 操作 TWebBrowser 实现自动填表(JQuery脚本与 OleVariant 方法)
版本:DELPHI XE8 操作交通银行信用卡申请表单(2016-03-23),网址如下: https://creditcardapp.bankcomm.com/applynew/front/appl ...
- 组队练习赛(Regionals 2012, North America - East Central NA)
A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...
- 启动Tomcat的几种方式
启动Tomcat有两种场景,一是部署时启动,二是开发时启动.部署时基本上是通过war包来启动,而开发时的启动方式多种多样,下面拟介绍几种适用于开发时启动Tomcat的方法. 在DOS命令行启动 Apa ...
- 网易云课堂_C++开发入门到精通_章节2:引用和函数的高级用法
课时6函数重载 函数重载 在C语言头文件中的extern "C" //常见的C语言头文件格式 #ifndef _FUNC_ #define _FUNC_ #ifdef __cplu ...
- 写一个产生16位纯数字唯一 ID 的方法,要求时间因素的介入。(不要求绝对唯一,在一定的时空中重复机率很小即可)
function randomID () { _random = function(min, max) { if (max == null) { max = min; min = 0; } retur ...
- 怎样在xcode中使用storyboard
StoryBoard是iOS 5的新特征,目的是取代历史悠久的NIB/XIB,对于已经习惯了xib文件的孩子们来说,StoryBoard还不是那么熟悉.经过两天的研究,有了一些心得,在此分享. 一.怎 ...
- 【网络协议】TCP的拥塞控制机制
前言 计算机网络中的带宽.交换节点中的缓存和处理机等,都是网络的资源,在某段时间内,若对网络中某一资源的需求超过了该资源所能提供的可用部分,网络的性能就要变坏,这样的情况就叫做拥塞. 所谓拥塞控制,就 ...
- EMCA创建em资料库时报错
说明:监听程序配置及启动正常.实例运行正常,远程或是本地sqlplus连接实例也正常.主机名显示正常,与主机名相关三个配置文件也没问题. emca报错: [oracle@rusky-oracle11g ...
- 向PHP语言进发
在做了几个月的.NET技术之后,我决定转去做PHP开发!人家都说,一言通,多言通!努力吧!