|  | 
| //------------------------------------------------------------------------------ //                                                                             -
 // 2015.03.20 by 龟山阿卍 QQ 1467948783                                        -
 // http://www.cnblogs.com/onechen/                                             -
 //                                                                             -
 //------------------------------------------------------------------------------
 
 unit Main;
 
 interface
 
 uses
 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
 FMX.ListView.Types, FMX.ListView, FMX.StdCtrls;
 
 type
 TForm1 = class(TForm)
 ToolBar1: TToolBar;
 Button1: TButton;
 ListView1: TListView;
 Label1: TLabel;
 procedure Button1Click(Sender: TObject);
 procedure ListView1UpdateObjects(const Sender: TObject;
 const AItem: TListViewItem);
 private
 { Private declarations }
 public
 { Public declarations }
 end;
 
 var
 Form1: TForm1;
 
 implementation
 
 {$R *.fmx}
 
 procedure TForm1.Button1Click(Sender: TObject);
 const DetailStr: array[0..2] of String =
 ('1234567890123456789012345678901234567890123456789012345678901234567890'
 ,'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
 ,'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
 );
 var i, r: Integer;
 Item1: TListViewItem;
 begin
 for i:=0 to 100 do
 begin
 Item1 := ListView1.Items.Add;
 r := Random(3);
 Item1.Detail := DetailStr[r].Substring(0, Random(DetailStr[r].Length));
 Item1.Text := i.ToString;
 end;
 end;
 
 procedure TForm1.ListView1UpdateObjects(const Sender: TObject;
 const AItem: TListViewItem);
 var R: TRectF;
 begin
 if (AItem.Objects.DetailObject <> nil) and
 (AItem.Objects.DetailObject.Text <> '') then
 begin
 // 计算文字显示的区域
 R := RectF(0, 0, AItem.Objects.DetailObject.Width, 10000);
 ListView1.Canvas.MeasureText(R,
 AItem.Objects.DetailObject.Text,
 AItem.Objects.DetailObject.WordWrap,
 [], TTextAlign.Leading, TTextAlign.Leading);
 
 // 设定高度
 AItem.Height := Trunc(R.Height);
 end;
 end;
 
 end.
 
 做下好人让大家可以直接看到内容
 
 
 | 
 |