功能:实现年月日压缩,初始化时item是所有年,点击年展开月,点击月展开天,再点击则收缩。

思路:实际上一开始是将所有item显示,只是将月日的item.height赋值为0,

     记录每一行的item的index,包括年,月,日,

   找到年的item,点击时,显示月的item,赋month.height即可,其他同理。

    接下来就是处理边界值。

unit listbox_test;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, StrUtils,
FMX.Layouts, FMX.ListBox, FMX.Memo, FMX.Controls.Presentation, FMX.ScrollBox; type
TListBoxFortest = class(TForm)
ListBox1: TListBox;
Layout1: TLayout;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure ListBox1ItemClick(const Sender: TCustomListBox;
const Item: TListBoxItem);
private
{ Private declarations } public
{ Public declarations }
end; var
ListBoxFortest: TListBoxFortest;
Year : Array[ 0..2 ] Of string = ('2015', '2014', '2013' );
Month : Array[ 0..3 ] Of Integer = (1, 2, 3, 4);
Day : Array[ 0..4 ] Of Integer = (10, 11, 12, 13, 14);
YearIndex : Array of Integer ;
MonthIndex : Array of Array of Integer ; //二维
ExpandYear : Integer;
ExpandMonth : Integer;
implementation {$R *.fmx} procedure TListBoxFortest.FormCreate(Sender: TObject);
var
yItem : TListBoxItem;
mItem : TListBoxItem;
dItem : TListBoxItem;
iyear : integer;
imonth : integer;
iday : integer;
begin
//设置默认值
ExpandYear := -1;
ExpandMonth := -1; //初始化长度
setlength(YearIndex, Length(Year));
setlength(MonthIndex, Length(Year), Length(Month)); with ListBox1 do begin
BeginUpdate;
for iyear := 0 to Length(Year) - 1 do begin
yItem := TListBoxItem.Create(nil);
yItem.Parent := ListBox1;
yItem.Name := 'year' + Year[iyear] ;
yItem.Text := 'year' + Year[iyear] ;
yItem.Height := 40;
YearIndex[iyear] := listbox1.Items.Count - 1; for imonth := 0 to Length(Month) - 1 do begin
mItem := TListBoxItem.Create(nil);
mItem.Parent := ListBox1;
mItem.Name := 'month' + Month[imonth].ToString ;
mItem.Text := ' month' + Month[imonth].ToString ;
mItem.Height := 0;
MonthIndex[iyear,imonth] := listbox1.Items.Count - 1; for iday := 0 to Length(Day) - 1 do begin
dItem := TListBoxItem.Create(nil);
dItem.Parent := ListBox1;
dItem.Name := 'day' + Day[iday].ToString ;
dItem.Text := ' day' + Day[iday].ToString ;
dItem.Height := 0;
end;
end;
end;
EndUpdate;
end; for iyear := 0 to Length(Year) - 1 do begin
self.Memo1.Lines.Add( 'year' + Year[iyear] + ' : ' + YearIndex[iyear].ToString);
for imonth := 0 to Length(Month) - 1 do begin
self.Memo1.Lines.Add( 'month' + Month[imonth].ToString + ' : ' + MonthIndex[iyear,imonth].ToString);
end;
end;
end; procedure TListBoxFortest.ListBox1ItemClick(const Sender: TCustomListBox;
const Item: TListBoxItem);
var
SeletedItemName : string;
SeletedItemIndex: Integer;
EndIndex : Integer;
FindItemIndex : Integer;
SubItemIndex : Integer;
temp : Integer;
temp_1 : Integer;
begin
SeletedItemName := ListBox1.ListItems[listBox1.ItemIndex].Name; //选中的item名
SeletedItemIndex := ListBox1.ListItems[listBox1.ItemIndex].Index; //选中的item索引 if LeftStr(SeletedItemName, 4) = 'year' then
begin
for FindItemIndex:=0 to Length(YearIndex) - 1 do
begin
if YearIndex[FindItemIndex] = SeletedItemIndex then //年的索引
break;
end; if ListBox1.ListItems[SeletedItemIndex + 1].Height = 30 then
ExpandYear := FindItemIndex
else
ExpandYear := -1; if ExpandYear <> -1 then
begin
if FindItemIndex = Length(YearIndex) - 1 then
EndIndex := ListBox1.Items.Count - 1
else
EndIndex := YearIndex[FindItemIndex + 1] - 1; with ListBox1 do begin
BeginUpdate;
for SubItemIndex := SeletedItemIndex + 1 to EndIndex do
begin
ListBox1.ListItems[SubItemIndex].Height := 0;
ListBox1.ListItems[SubItemIndex].Visible := false;
end;
EndUpdate;
end;
ExpandYear := -1;
end
else
begin
temp := Length(MonthIndex[FindItemIndex]); // 选中的该年 月索引的个数
with ListBox1 do begin
BeginUpdate;
for SubItemIndex := 0 to temp - 1 do
begin
temp_1 := MonthIndex[FindItemIndex,SubItemIndex]; // 遍历选中的Item下一级(月)的每个itemindex
ListBox1.ListItems[temp_1].Height := 30;
ListBox1.ListItems[temp_1].Visible := true;
end;
ExpandYear := FindItemIndex; // 展开年的ItemIndex
EndUpdate;
end;
end;
end; for temp := 0 to Length(Year) - 1 do
for temp_1 := 0 to Length(Month) - 1 do
if SeletedItemIndex = MonthIndex[temp,temp_1] then begin
ExpandYear := temp; // 展开的年itemindex
break;
end; if (LeftStr(SeletedItemName,5) = 'month') and (ExpandYear <> -1) then
begin
temp := Length(MonthIndex[ExpandYear]);
for FindItemIndex := 0 to temp - 1 do
begin
if MonthIndex[ExpandYear, FindItemIndex] = SeletedItemIndex then // 展开的月itemindex
break;
end; if ListBox1.ListItems[SeletedItemIndex + 1].Height = 30 then
ExpandMonth := FindItemIndex
else
ExpandMonth := -1; if FindItemIndex <> temp -1 then // 处理边界值
EndIndex := MonthIndex[ExpandYear, FindItemIndex + 1] - 1 // 该月中天的最后索引
else begin
if ExpandYear <> Length(Year) - 1 then
EndIndex := YearIndex[ExpandYear + 1] - 1
else
EndIndex := listBox1.Items.Count - 1;
end; // 天的索引为月点击(SubItemIndex)MItemIndex+1 - 下一个(EndIndex)MItemIndex + 1 之间的索引
with ListBox1 do
begin
BeginUpdate;
for SubItemIndex := MonthIndex[ExpandYear, FindItemIndex] + 1 to EndIndex do // 将该月的下一级从第一个到最后一个遍历显示
begin
if ExpandMonth = -1 then
begin
ListBox1.ListItems[SubItemIndex].Height := 30;
ListBox1.ListItems[SubItemIndex].Visible := true;
end
else
begin
ListBox1.ListItems[SubItemIndex].Height := 0;
ListBox1.ListItems[SubItemIndex].Visible := false;
end;
end;
if ExpandMonth = -1 then
ExpandMonth := FindItemIndex
else
ExpandMonth := -1;
EndUpdate;
end;
end;
end; end.

XE ListBox实现伸缩效果的更多相关文章

  1. jQuery-手风琴伸缩效果

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. Android 浮动按钮的伸缩效果

    在做项目时想增加点动感,于是就有如下效果: 实现起来也很简单,通过属性动画和recyclerview 滑动结合就很好实现了. 通过给recycleview添加一个滑动监听:通过滚动的差值来处理动画 m ...

  3. jQuery实现的表格展开伸缩效果实例

    <table> <thead> <tr> <th>姓名</th> <th>性别</th> <th>暂住地 ...

  4. ZK listbox 两种分页使用及比较

    参考:http://tsinglongwu.iteye.com/blog/849923 以下代码模拟数据量大时情况,采用“<paging>”组件方式 前台Listbox.zul : < ...

  5. Android两个页面之间的切换效果工具类

    import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; ...

  6. WPF自定义控件与样式(6)-ScrollViewer与ListBox自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Scr ...

  7. css 使用background背景实现border边框效果

    css中,我们一般使用border给html元素设置边框,但也可以使用background背景来模拟css边框效果,本文章向大家介绍css 使用background背景实现border边框效果,需要的 ...

  8. xe5 android listbox的 TMetropolisUIListBoxItem

    listbox实现以下效果: 关键代码,采用数据集的方式 type PpatientData=^RpatientData; RpatientData= record patient_id:string ...

  9. delphi xe5 android listbox的 TMetropolisUIListBoxItem

    listbox实现以下效果: \ 关键代码,采用数据集的方式 type PpatientData=^RpatientData; RpatientData= record patient_id:stri ...

随机推荐

  1. Linux 安装交叉编译工具链

    交叉编译工具链下载地址: 链接:http://pan.baidu.com/s/1dE7P9rb 密码:300i 声明:下面每一步中的“pwd”指令都是为了看清楚当前的目录,没有其他实际意义. 系统:u ...

  2. cpu 核数及逻辑数统计

    查看逻辑CPU个数:cat /proc/cpuinfo |grep "processor"|sort -u|wc -l24 查看物理CPU个数:grep "physica ...

  3. MSSQL使用sqlbulkcopy批量插入数据

    具体代码如下: /// <summary> /// 批量插入数据到BayonetZipFailedPic表 /// </summary> /// <param name= ...

  4. 别人的dubbo学习笔记

    本文转载自:http://blog.csdn.net/tao_qq/article/details/49952229 学习dubbo,开始做一些笔记. 1> 启动dubbo-admin模块的时候 ...

  5. Python print format() 格式化内置函数

    Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前的 % . format 函数可以接受不限个参数 ...

  6. python学习(十一) 文件和流

    11.1 打开文件 >>> f = open(r'c:\text\somefile.txt'),  第一个参数是文件名,必须有:第二个是模式:第三个参数是缓冲. 11.1.1 文件模 ...

  7. Unity3D的坑系列:你真想发布WinPhone版吗?

    Unity 4.2加入了支持WinPhone发布,本来是一件令人开心的事情,不过最近听了Unity技术支持的一个事情后就发现,原来发布WinPhone版也是一个坑. 实际上如果你用Unity做小游戏发 ...

  8. Linux - rpm 软件包管理

    rpm 是 Red-Hat Package Manager(rpm 软件包管理器)的缩写 rpm 的命名规则: 第一部分为 rpm 软件包的名称,第二部分是版本号,第三部分是版本发布次数,第四部分是软 ...

  9. linux安装xgboost

    在学校服务器上安装xgboost,事先我已经安装了anaconda,但是因为师兄已经装了python所以没加入到path. 网上的方法一般都要编译,另外官方的下载方法要联网..总之出了一堆错,最终还是 ...

  10. Leetcode:Merge k Sorted Lists分析和实现

    题目大意是传入一个链表数组lists,每个链表都由若干个链接的链表结点组成,并且每个链表结点记录一个整数.题目保证传入的链表中的整数按从小到大进行排序. 题目要求我们输出一个新的链表,这个链表中应该包 ...