Delphi(Pascal) codeunit Unit1
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls
type
TForm1 = class(TForm)
ListView1: TListView
Timer1: TTimer
procedure FormCreate(Sender: TObject)
procedure ListView1CustomDrawSubItem(Sender: TCustomListView
Item: TListItemSubItem: IntegerState: TCustomDrawState
var DefaultDraw: Boolean)
procedure Timer1Timer(Sender: TObject)
private
{ Private declarations }
FProgress: TListItem
FPostion: Integer
FLength: Integer
FProgressRect: TRect
public
{ Public declarations }
end
var
Form1: TForm1
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject)
begin
FProgress := ListView1.Items.Add
FProgress.Caption := 'temp.txt'
FPostion := 0
FLength := 100
Timer1.Interval := 100
end
procedure DrawProgress(ACanvas: TCanvasARect: TRect
APostion, ALength: Integer)// 想绘制得漂亮些就在这里修改。
begin
ACanvas.Brush.Color := clWindow
ACanvas.FillRect(ARect)
ACanvas.Brush.Color := clHighlight
ACanvas.FillRect(Rect(ARect.Left, ARect.Top + 2,
ARect.Left + Trunc((ARect.Right - ARect.Left) * (APostion / ALength)),
ARect.Bottom - 4))
end
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView
Item: TListItemSubItem: IntegerState: TCustomDrawState
var DefaultDraw: Boolean)
begin
if FProgress <>Item then Exit
if Item.Index <>0 then Exit
FProgressRect := Item.DisplayRect(drBounds)
FProgressRect.Left := Sender.Column[0].Width
FProgressRect.Right := Sender.Column[1].Width + FProgressRect.Left
///////End 计算进度条绘制的区域
DrawProgress(Sender.Canvas, FProgressRect, FPostion, FLength)
DefaultDraw := False
end
procedure TForm1.Timer1Timer(Sender: TObject)
begin
FPostion := (FPostion + 1) mod FLength
DrawProgress(ListView1.Canvas, FProgressRect, FPostion, FLength)
end
end.
exList就是listview ,其中的每个item中都有一个progressBarprogress是进度;
View v = exList.getChildAt(i)
ProgressBar bar = (ProgressBar) v .findViewById(R.id.manager_loading_progress_bar)
if (bar != null)
bar.setProgress(progress)
我以前的做法是: 在BaseAdapter中每创建一个View时候 就把每一个progressbar加到list中。 当我加载完所有item后, 所有的progressbar都在list中,你想改哪一个就得到哪一个的progressbar不知道对你有没有用?欢迎分享,转载请注明来源:内存溢出
评论列表(0条)