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 ...
随机推荐
- An invalid form control with name='timeone[]' is not focusable.
在项目开发的时候 遇到了这样的报错 An invalid form control with name='timeone[]' is not focusable. 学习源头:https://segme ...
- week-02 线性表
一.PTA实验作业 题目1:顺序表 7-1 最长连续递增子序列 1. 设计思路 定义结构体List,定义数组Data[maxsize]表示顺序表元素,变量Position表示位置,变量Length表示 ...
- druid抛出异常:javax.management.InstanceAlreadyExistsException: com.alibaba.druid:type=DruidDataSource,id=xxx
第一种结论 (参考: https://www.cnblogs.com/youzhibing/p/6826767.html): 问题产生的根本原因还真是:同一实例被启动了两遍,Path为/SLBAdmi ...
- Oracle用游标删除重复数据
CREATE OR REPLACE PROCEDURE PR_MOD_BASE IS cursor c_base IS SELECT MIN(INVENTORY_DATE) IDATE,KUNNR,M ...
- 庖丁解牛-----Live555源码彻底解密(根据MediaServer讲解Rtsp的建立过程)
live555MediaServer.cpp服务端源码讲解 int main(int argc, char** argv) { // Begin by setting up our usage env ...
- jenkins获取测试报告展示的方法
1.写好了可以生成报告的python文件 2.在jenkins里下载 HTML Publisher plugin 插件 系统管理--管理插件--选择[可选插件]tab---搜索HTML Publis ...
- AngularJS:过滤器
ylbtech-AngularJS:过滤器 1.返回顶部 1. AngularJS 过滤器 过滤器可以使用一个管道字符(|)添加到表达式和指令中. AngularJS 过滤器 AngularJS 过滤 ...
- 微信小程序之如何使用iconfont
如何在小程序中使用iconfont 1.添加入库 2.加入项目 3.下载ttf 4.进行base64处理,在这个平台https://transfonter.org/ 上转换一下格式为base64位. ...
- 字符串,字符数组(C/C++)
这个地方困惑我好久了,废话不多说 char c1[]="12345"; char *c2="12345"; string c3="12345" ...
- CentOS yum 安装RabbitMQ
最近在做机器学习的任务系统,任务模块使用了消息对联,比较快速的搭建方法: 1.安装erlang 下载rpm仓库:wget http://packages.erlang-solutions.com/er ...