如何自定义下拉刷新的listview

如何自定义下拉刷新的listview,第1张

1 . 用LinearLayout包裹一个refreshHeadView和一个listView , 触摸时通过改变refreshHeadView的LayoutParams参数的 topMargin来隐藏和显示refreshHeadView,lp.topMargin = - refreshHeadHeight 时,头部隐藏,lp.topMargin = 0 时,头部恰好完全出现。我的另外一篇博客实现了这个思路

[ http://blog.csdn.net/u010335298/article/details/50956995 ]

2 . 用ListView的addHeaderView方法,为ListView设置一个headView作为下拉刷新的view ,通过设置headView的topPadding来显示和隐藏headView , topPadding = - headHeight的时候,headView隐藏,topPadding = 0 时 ,头部恰好完全出现 。这篇博客就是用这种思路实现的

先说明一点,本事例单击是在listview的每一次第一列出一个下拉列表框,要在其他列出现,可能要用GetCursorPos(pos)来确置了,你自己完善吧,哈哈!

unit Unit1

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

ComCtrls, StdCtrls

type

TForm1 = class(TForm)

ListView1: TListView

ComboBox1: TComboBox

procedure FormDestroy(Sender: TObject)

procedure ListView1Click(Sender: TObject)

private

FComboBox: TComboBox

{ Private declarations }

procedure CreateCombobox(var aComboBox:TComboboxaLeft, aTop: integer)

procedure MyComboBoxChange(Sender: TObject)

procedure MyComboBoxExit(Sender: TObject)

public

{ Public declarations }

end

var

Form1: TForm1

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.CreateCombobox(var aComboBox: TCombobox

aLeft, aTop: integer)

begin

aComboBox := TComboBox.Create(Self)

aComboBox.Parent := Self

aComboBox.OnChange := MyComboBoxChange

aComboBox.OnExit := MyComboBoxExit

aComboBox.DropDownCount := 5

aComboBox.Style := csDropDown

aComboBox.Items.Add('字段')

aComboBox.Items.Add('aaa')

aComboBox.Items.Add('bbb')

aComboBox.Items.Add('ccc')

aComboBox.Items.Add('其他类型')

aComboBox.Left := aLeft + ListView1.Left + 1

aComboBox.Top := aTop + ListView1.Top + 1

aComboBox.Width := 50

aComboBox.BringToFront

aComboBox.SetFocus

end

procedure TForm1.MyComboBoxChange(Sender: TObject)

begin

if Assigned(ListView1.Selected) then

ListView1.Selected.Caption := TCombobox(Sender).Text

end

procedure TForm1.MyComboBoxExit(Sender: TObject)

begin

try

FComboBox.Free

except

end

FComboBox := nil

end

procedure TForm1.FormDestroy(Sender: TObject)

var

lp: integer

begin

for lp := ComponentCount - 1 downto 0 do

begin

if Components[lp] is TCombobox then

begin

TCombobox(Components[lp]).Free

end

end

FComboBox := nil

end

procedure TForm1.ListView1Click(Sender: TObject)

begin

FormDestroy(Sender)

if Assigned(ListView1.Selected) then

CreateCombobox(FComboBox, ListView1.Selected.Left, ListView1.Selected.Top)

end

end.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11972158.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存