ListCell Animation in ListView
After a long time I am back again with new stuffs. I have seen that JavaFX has got so many demand nowadays. Lots of people are requesting for something new something wow effect. In the same way one of my colleagues told me what if we have listview got some effects on scrolling the list. I got some dig around JavaFX Animation API and did some animation with ListCell but I thought it would be great if I share my works to you guys.
First We got to revamp what is the Listcell. ListCell are designed for making user to display text content in list format. But we can override these and make our own like displaying images,shapes and other controls as well.
ListCell inherits the character of Labeled so in default ListCell only displays the text content.If you want some control in your listcell other than label then there are some bunch of cellfactory in javafx.scene.control.cell package.
Every ListCell are being rendered according to the cellFactory implementation so you are free to implement your own cellFactory to make the listcell even more customizable. I had posted about TableCell customization which utilizes use of cellFactory (TableView Cell Modify)
Lets roll with the ListCell customization.
——————————————————————————————————————————————————————
public class AnimatedListCell<T> extends AbstractAnimatedListCell<T> { //... other codes ...
/**
* Get cellfactory of AbstractAnimatedListCell for ListView
*
* @param type
* @return
*/
public static Callback<ListView<String>, ListCell<String>> forListView(final AnimationType... type) {
return new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(
ListView<String> p) {
return new AnimatedListCell<>(new DefaultStringConverter(), type);
}
};
} /**
* Get cellfactory of AbstractAnimatedListCell for ListView with StringConverter
*
* @param <T>
* @param sc
* @param type
* @return
*/
public static <T extends Object> Callback<ListView<T>, ListCell<T>> forListView(
final StringConverter<T> sc, final AnimationType... type) {
return new Callback<ListView<T>, ListCell<T>>() {
@Override
public ListCell<T> call(
ListView<T> p) {
return new AnimatedListCell<>(sc, type);
}
}; } /**
* For getting the KeyFrames of specific AnimationType
*
* @param types
* @return
*/
@Override
protected KeyFrame[] getKeyFrames(AnimationType[] types) {
if (types == null) {
return null;
}
KeyFrame[] frames = null;
for (AnimationType type : types) {
switch (type) {
case FADE_OUT:
frames = anim.getFadeOut(frames);
break;
case FLAP_RIGHT:
frames = anim.getFlapRight(frames);
break;
case FLATTERN_OUT:
frames = anim.getFlatternOut(frames);
break;
case FLY_FROM_DOWN:
frames = anim.getFlyFromDown(frames);
break;
case FLY_FROM_UP:
frames = anim.getFlyFromUp(frames);
break;
case ROTATE_RIGHT:
frames = anim.getRotateYRight(frames);
break;
case SPEED_LEFT:
frames = anim.getSpeedLeft(frames);
break;
case SPEED_RIGHT:
frames = anim.getSpeedRight(frames);
break;
case TRANSITION_DOWN:
frames = anim.getTransitionDown(frames);
break;
case TRANSITION_LEFT:
frames = anim.getTransitionLeft(frames);
break;
case TRANSITION_RIGHT:
frames = anim.getTransitionRight(frames);
break;
case TRANSITION_TOP:
frames = anim.getTransitionTop(frames);
break;
case ZOOM_IN:
frames = anim.getZoomIn(0, frames);
break;
case POP_OUT:
frames = anim.getPopOut(frames);
break; }
}
return frames; } @Override
protected void updateItem(T t, boolean bln) {
//overriding the super interface
super.updateItem(t, bln); }
}
Above Class is subclass of AbstractAnimatedListCell so you can implement this in your cellFactory. Currently AbstractAnimatedListCell is subclass of ListCell which helps to make the animation possible. Now Lets directly move to the animation implementation.
/**
*
* @author Narayan G. Maharjan <me@ngopal.com.np>
*/
public class ListViewAnimation extends Application {
ObservableList list = FXCollections.observableArrayList(); ListView<String> listView; ComboBox<AnimationType> box; HBox hbox; AnchorPane root; Button btn; /**
* For initializing Containers
*/
public void initContainers() {
root = new AnchorPane();
hbox = new HBox(10); AnchorPane.setBottomAnchor(listView, 50d);
AnchorPane.setTopAnchor(listView, 10d);
AnchorPane.setLeftAnchor(listView, 10d);
AnchorPane.setRightAnchor(listView, 10d);
AnchorPane.setBottomAnchor(hbox, 10d);
AnchorPane.setLeftAnchor(hbox, 10d);
} /**
* For initializing controls
*/
public void initControls() {
listView = new ListView<>();
listView.setCellFactory(AnimatedListCell.forListView(AnimationType.ROTATE_RIGHT, AnimationType.FADE_OUT)); box = new ComboBox<>();
box.valueProperty().addListener(new ChangeListener<AnimationType>() {
@Override
public void changed(
ObservableValue<? extends AnimationType> ov, AnimationType t, AnimationType t1) {
if (!t1.equals(t)) {
listView.setCellFactory(AnimatedListCell.forListView(t1));
}
}
}); btn = new Button("Add New");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
list.add("Added New");
}
}); } @Override
public void start(Stage stage) throws Exception {
//Loading custom fonts
Font.loadFont(getClass().getResource("fonts/segoesc.ttf").toExternalForm(), 12); //adding values to list
for (int i = 0; i < 10; i++) {
list.add("" + i);
} //Initializing Controls
initControls();
initContainers(); //Adding Values
listView.setItems(list);
box.getItems().addAll(AnimationType.values()); //Adding controls to container
hbox.getChildren().addAll(new Label("Animation Type:"), box, btn);
root.getChildren().addAll(listView, hbox); Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("css/style.css").toExternalForm());
scene.setCamera(new PerspectiveCamera());
stage.setTitle("List Animation!");
stage.setScene(scene);
stage.show(); } public static void main(String[] args) {
launch(args);
}
}
Well after implementing those Animation you can get animation instantly on list cell update . However I have added some few styling to make it even more better.
If you want to try out yourself . Grab the source code from here:
ListCell Animation in ListView的更多相关文章
- Animation显示ListView的每一条记录
activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...
- Android5.0 ListView特效的简单实现
Android5.0中对于动画可所谓是情有独钟,在设计规范中大量展现了listview的动画,其实也就是一个目的:将items动画显示出来.这个看起来很炫的效果,其实实现也蛮简单的,我下面就来用动画简 ...
- android3D动画,绕y轴旋转
原文地址:http://blog.csdn.net/x_i_a_o_h_a_i/article/details/40449847 其实网上的3D旋转的例子很多,在这里我只是想把其代码做一个解释. 先上 ...
- Android中轴旋转特效实现,制作别样的图片浏览器
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/10766017 Android API Demos中有很多非常Nice的例子,这些例 ...
- javaFX笔记----ComboBox模仿qq账号下拉框删除账号
myComboBox.setCellFactory( new Callback<ListView<String>, ListCell<String>>() { @O ...
- javafx ComboBox Event and change cell color
public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...
- ListView Animation
简单介绍一下4种动画效果方式AnimationSet set = new AnimationSet(false); Animation animation = new AlphaAnimation(0 ...
- ListView的淡入淡出和Activity的淡入淡出补间动画效果Animation
//=========主页面======================= package com.bw.lianxi7; import android.os.Bundle;import androi ...
- Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一Item项的显示动画
前言: 之前,我已经写了两篇博文,给大家介绍了Android的基础动画是如何实现的,如果还不清楚的,可以点击查看:Android Animation动画详解(一): 补间动画 及 Android An ...
随机推荐
- Android:将View的内容映射成Bitmap转图片导出
前段时间在网上看到这么个例子是将view映射到一个bitmap中,稍加改进可以用于一些截图工具或者截图软件(QQ截图之类),例子写的不够完善,不过很有些学习的意义内容大致如下: 在Android中自有 ...
- 【笨嘴拙舌WINDOWS】键盘消息,鼠标消息
键盘消息 Windows系统无论何时只有一个窗口(可能是子窗口,也就是控件)能获得焦点. 焦点窗口通过windows消息来响应人的键盘操作,与键盘相关的常用消息罗列如下: WM_KEYDOWN 按 ...
- svn备份脚 本
一直用这套脚本备份,脚本主体虽不是原创,但是从网上得到后因为不能运行也进行了些修改,前两天看到有人问关于SVN备份的问题,今天又把脚本整理了一下,解决了不能循环备份多个配置库的问题.希望对大家有所帮助 ...
- PHP设计模式之装饰者模式
<?php /* 装饰者模式动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更有弹性的替代方案. */ header("Content-type:text/html; cha ...
- 【转】DB2 常用命令
1. 打开命令行窗口 #db2cmd 2. 打开控制中心 # db2cmd db2cc 3. 打开命令编辑器 db2cmd db2ce =====操作数据库命令===== 4. 启动数据库实例 ...
- AIX系统管理员--第一章笔记
IBM产品系列 x系类为PC服务器-- e-server x x表示x-architecture 可自由选择运行环境,windows.linux.unix等 p系类为 ...
- Heritrix源码分析(十四) 如何让Heritrix不间断的抓取(转)
欢迎加入Heritrix群(QQ):109148319,10447185 , Lucene/Solr群(QQ) : 118972724 本博客已迁移到本人独立博客: http://www.yun5u ...
- Python网页解析
续上篇文章,网页抓取到手之后就是解析网页了. 在Python中解析网页的库不少,我最开始使用的是BeautifulSoup,貌似这个也是Python中最知名的HTML解析库.它主要的特点就是容错性很好 ...
- 如何正确选择MySQL数据列类型
MySQL数据列类型选择是在我们设计表的时候经常会遇到的问题,下面就教您如何正确选择MySQL数据列类型,供您参考学习. 选择正确的数据列类型能大大提高数据库的性能和使数据库具有高扩展性.在选择MyS ...
- 微信支付-JSAPI支付V3-查询退款
接口地址 接口链接:https://api.mch.weixin.qq.com/pay/refundquery 是否需要证书 不需要. 请求参数 字段名 变量名 必填 类型 示例值 描述 公众账号ID ...