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 ...
随机推荐
- linux用rdate命令实现同步时间
用rdate命令实现同步时间 前两天说到用ntp时间服务器和ntpdate命令同步时间,今天简单记录下用rdate同步时间 http://blog.csdn.net/wyzxg/archive/201 ...
- 安装appium需要注意的事项
参考 虫师 的博客园 :http://www.cnblogs.com/fnng/p/4560298.html 1.其中第二篇中,打开命令行用的不是windows中的cmd打开的界面,而是用node. ...
- AngularJS:Service
ylbtech-AngularJS:Service 1.返回顶部 1. AngularJS 服务(Service) AngularJS 中你可以创建自己的服务,或使用内建服务. 什么是服务? 在 An ...
- python开发mysql:单表查询&多表查询
一 单表查询,以下是表内容 一 having 过滤 1.1 having和where select * from emp where id > 15; 解析过程;from > where ...
- python2 encode和decode函数说明
字符串编码常用类型:utf-8,gb2312,cp936,gbk等. python中,我们使用decode()和encode()来进行解码和编码 在python中,使用unicode类型作为编码的基础 ...
- springboot成神之——spring boot,spring jdbc和spring transaction的使用
本文介绍spring boot,spring jdbc和spring transaction的使用 项目结构 依赖 application model层 mapper层 dao层 exception层 ...
- MAPREDUCE的实战案例
reduce端join算法实现 1.需求: 订单数据表t_order: id date pid amount 1001 20150710 P0001 2 1002 20150710 P0001 3 1 ...
- delphi IOS发布添加其他资源文件
添加自己的文件. Project>Deployment>Add File Remote Path android and IOS: assets\internal\ TPath.GetDo ...
- Python基础学习四 列表、元组、字典、集合
列表list,用中括号“[ ]”表示 1.任意对象的有序集合 列表是一组任意类型的值,按照一定顺序组合而成的 2.通过偏移读取 组成列表的值叫做元素(Elements).每一个元素被标识一个索引,第一 ...
- mysql 批量插入与单条插入 的效率比较
1.数据插入性能(单个插入和批量插入) public class Test { private Long id; private String test; public Long getId() { ...