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的更多相关文章

  1. Animation显示ListView的每一条记录

    activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

  2. Android5.0 ListView特效的简单实现

    Android5.0中对于动画可所谓是情有独钟,在设计规范中大量展现了listview的动画,其实也就是一个目的:将items动画显示出来.这个看起来很炫的效果,其实实现也蛮简单的,我下面就来用动画简 ...

  3. android3D动画,绕y轴旋转

    原文地址:http://blog.csdn.net/x_i_a_o_h_a_i/article/details/40449847 其实网上的3D旋转的例子很多,在这里我只是想把其代码做一个解释. 先上 ...

  4. Android中轴旋转特效实现,制作别样的图片浏览器

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/10766017 Android API Demos中有很多非常Nice的例子,这些例 ...

  5. javaFX笔记----ComboBox模仿qq账号下拉框删除账号

    myComboBox.setCellFactory( new Callback<ListView<String>, ListCell<String>>() { @O ...

  6. javafx ComboBox Event and change cell color

    public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...

  7. ListView Animation

    简单介绍一下4种动画效果方式AnimationSet set = new AnimationSet(false); Animation animation = new AlphaAnimation(0 ...

  8. ListView的淡入淡出和Activity的淡入淡出补间动画效果Animation

    //=========主页面======================= package com.bw.lianxi7; import android.os.Bundle;import androi ...

  9. Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一Item项的显示动画

    前言: 之前,我已经写了两篇博文,给大家介绍了Android的基础动画是如何实现的,如果还不清楚的,可以点击查看:Android Animation动画详解(一): 补间动画 及 Android An ...

随机推荐

  1. Microsoft.ACE.OLEDB.12.0 错误 上传读取Excel错误

    使用"Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filePath + ";&quo ...

  2. 单点登录系统构建之二——SSO原理及CAS架构

    基本概念 SSO(Single Sign On)单点登录,是在多个应用系统中,用户只需要登录一次就能访问所有相互信任的应用系统.它包括将这次的主要登录映射到其他应用中用户同一个用户的登录机制. SSO ...

  3. Asp.Net生命周期系列三

    上文讲到了HttpRunTime主要做了三个事情,我们先回忆一下. 第一:雇佣了项目经理(HttpApplication). 第二:建立了HttpModule列表,项目经理(HttpRunTime)就 ...

  4. win32窗口机制之CreateWindow

    CreateWindow     函数功能:该函数创建一个重叠式窗口.弹出式窗口或子窗口.它指定窗口类,窗口标题,窗口   风格,以及窗口的初始位置及大小(可选的).该函数也指定该窗口的父窗口或所属窗 ...

  5. 打印Dom对象的所有属性和方法

    <html> <head> <title>Test</title> <meta http-equiv="Content-Type&quo ...

  6. xp关不了机

    自己测试:按第2点的设置既可成功1.点“开始→设置→控制面板→电源选项→高级电源管理”,如果你的机器支持高级电源管理功能,则选中“启用高级电源管理支持”:2.单击“开始”,并运行“regedit”,然 ...

  7. QR二维码(转)

    二维码又称QR Code,QR全称Quick Response,是一个近几年来移动设备上超流行的一种编码方式,它比传统的Bar Code条形码能存更多的信息,也能表示更多的数据类型:比如:字符,数字, ...

  8. phonegap 退出确认

    实现 再按一次退出  ,这里只针对 主active继承 DroidGap 或者CordovaActive 以下有2种 方案1: 重写CordovaWebView类 新建类NobackWebView p ...

  9. HDU 4608 I-number 2013 Multi-University Training Contest 1

    定义一个数 y 为 x 的 I-number.对于 y 有如下要求: 1.y > x; 2.y 的每一位之和要为10的倍数(例如 28 每一位之和为 10 ,为 10 的 1 倍); 3.这样的 ...

  10. mysql 概念和逻辑架构

    1.MySQL整体逻辑架构 mysql 数据库的逻辑架构如下图: 第一层,即最上一层,所包含的服务并不是MySQL所独有的技术.它们都是服务于C/S程序或者是这些程序所需要的 :连接处理,身份验证,安 ...