功能:实现年月日压缩,初始化时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. 关于OPC自动化接口编程(OPCDAAuto.dll)几点注意问题

    为了能够在工作中方便的应用OPC和充分的理解OPC的开发流程.内部机制,这两天正在研究开发OPC客户端程序,一般我们开发OPC客户端程序有以下几种方式: (1)       使用OPCNetAPI,需 ...

  2. nginx.conf自己整理的中文解读

    自己收集了网上有关conf文件的中文详解,这样以后就不怕看不懂nginx的配置文件啦! #定义Nginx运行的用户和用户组user www www; #nginx进程数,建议设置为等于CPU总核心数. ...

  3. PhantomJS 一个隐形的浏览器

    下载地址: http://phantomjs.org/download.html 使用方法: 下载压缩包解压出来找到phantomjs.exe 放到python的根目录下

  4. memcache常见问题及解答

    memcached的cache机制是怎样的? Memcached主要的cache机制是LRU(最近最少用)算法+超时失效.当您存数据到memcached中,可以指定该数据在缓存中可以呆多久Which ...

  5. 实例甜点 Unreal Engine 4迷你教程(3)之用C++改变Image小部件的其它属性

    完成本迷你教程之前,请前往完成以下迷你教程: ·实例甜点 Unreal Engine 4迷你教程(2)之用C++改变Image小部件的颜色: 在上一次的迷你教程的LearnWidgets工程上进行(如 ...

  6. python对裤子进行一个查询

    前言: 获取到一个数据库,使用python对其 进简单的查询 代码: import time print('开房记录查询') def chax(): g=input('请输入要查询的>>& ...

  7. oracle 11g 导出空表

    正常情况下,oracle11g的 exp命令无法导出空表,弥补这个缺陷的方法是 在空表创建之前,更改系统设置: show parameter deferred_segment_creation 查看, ...

  8. div+css 左右两列自适应高度 ,以及父级div也跟着自适应子级的高度(兼容各大浏览器)

    <style type="text/css" media="screen"> <!-- #main {width:500px;_height: ...

  9. 02-20 winform 上传图片并读取图片

    建立一个windows窗体应用程序,在form1界面中拖入两个按钮和一个pictureBox,通过输入输出流来上传图片和显示图片.需要添加一下openFileDialog1. 界面如下: 在cs中写上 ...

  10. CBV中的dispatch

    之前介绍了FBV和CBV ,下面我们看一下CBV中的dispatch dispatch函数在类View中定义,作用就是通过反射查找get或post函数,所以在执行get或post函数之前,dispat ...