XE ListBox实现伸缩效果
功能:实现年月日压缩,初始化时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实现伸缩效果的更多相关文章
- jQuery-手风琴伸缩效果
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Android 浮动按钮的伸缩效果
在做项目时想增加点动感,于是就有如下效果: 实现起来也很简单,通过属性动画和recyclerview 滑动结合就很好实现了. 通过给recycleview添加一个滑动监听:通过滚动的差值来处理动画 m ...
- jQuery实现的表格展开伸缩效果实例
<table> <thead> <tr> <th>姓名</th> <th>性别</th> <th>暂住地 ...
- ZK listbox 两种分页使用及比较
参考:http://tsinglongwu.iteye.com/blog/849923 以下代码模拟数据量大时情况,采用“<paging>”组件方式 前台Listbox.zul : < ...
- Android两个页面之间的切换效果工具类
import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; ...
- WPF自定义控件与样式(6)-ScrollViewer与ListBox自定义样式
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Scr ...
- css 使用background背景实现border边框效果
css中,我们一般使用border给html元素设置边框,但也可以使用background背景来模拟css边框效果,本文章向大家介绍css 使用background背景实现border边框效果,需要的 ...
- xe5 android listbox的 TMetropolisUIListBoxItem
listbox实现以下效果: 关键代码,采用数据集的方式 type PpatientData=^RpatientData; RpatientData= record patient_id:string ...
- delphi xe5 android listbox的 TMetropolisUIListBoxItem
listbox实现以下效果: \ 关键代码,采用数据集的方式 type PpatientData=^RpatientData; RpatientData= record patient_id:stri ...
随机推荐
- 2、通过HBase API进行开发
一.将HBase的jar包及hbase-site.xml添加到IDE 1.到安装HBase集群的任意一台机器上找到HBase的安装目录,到lib目录下下载HBase需要的jar包,然后再到conf目录 ...
- awk 内容
awk相关内容 #只要文件中的路径,不要文件名: [ ...
- PCB打样前的注意事项
0.画板前,在制定规则的时候,一定要查看生产厂家的生产工艺. (厂家能打几层板.最小间距.焊盘最小和最大尺寸等等) 1.查看焊盘的孔径是否合适. (检查能否插进去) 2.仔细检查购买的三端器件的引 ...
- PHP函数(一)-变量
1.全局变量 <?php $a = 1; $b = 2; function test(){ echo $a + $b."<br>"; //运行结果为0 } tes ...
- python's twenty-third day for me 面向对象进阶
普通方法:对象和类绑定的过程. class A: def func1(self):pass def func2(self):pass def func3(self):pass def func4(se ...
- storm集群配置以及java编写拓扑例子
storm集群配置 安装 修改配置文件 使用java编写拓扑 storm集群配置 storm配置相当简单 安装 tar -zxvf apache-storm-1.2.2.tar.gz rm apach ...
- 使用ReentrantReadWriteLock类
读读共享 类ReentrantReadWriteLock的使用:写写互斥 读写互斥
- Spring AOP基于注解的“零配置”方式实现
为了在Spring中启动@AspectJ支持,需要在类加载路径下新增两个AspectJ库:aspectjweaver.jar和aspectjrt.jar.除此之外,Spring AOP还需要依赖一个a ...
- 【基础巩固】文件流读写、大文件移动 FileStream StreamWriter File Path Directory/ ,m资料管理器(递归)
C#获取文件名 扩展名 string fullPath = @"d:\test\default.avi"; string filename = Path.GetFileName(f ...
- 配置Linux的SSH双重认证
背景:双因子认证(简称:2FA,以下简称2FA),在这里其为SSH的第二重认证.2FA指的是密码以及实物(信用卡.SMS手机.令牌或指纹等生物标志)两种条件对用户进行认证的方法.通过两种不同的认证程序 ...