zoukankan      html  css  js  c++  java
  • ListView 下拉更新 (支持 Android)

    注意:XE7 已提供下拉更的功能。

    说明:展示如何在 Android 平台下,使用 ListView 下拉更新。

    适用:Delphi XE5 , XE6

    修改:需要修改到 Delphi 源码 FMX.Platform.Android.pas,请见:[原创] 让 ListView 在 Android 可回弹 

    视频:http://v.youku.com/v_show/id_XNjU1MzExMDY0.html

    源码下载:[原创]ListView下拉更新_XE5.zip

    源码下载:[原创]ListView下拉更新_XE6.zip

    //------------------------------------------------------------------------------
    // 2013.12.30 by 龟山阿卍 QQ 1467948783                                        -
    // http://www.cnblogs.com/onechen/                                             -
    //                                                                             -
    // 需修改                                                                      -
    // FMX.Platform.Android.pas                                                    -
    // function TPlatformAndroid.GetScrollingBehaviour: TScrollingBehaviours;      -
    //------------------------------------------------------------------------------
    
    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.StdCtrls,
      FMX.ListView.Types, FMX.Objects, FMX.ListView, FMX.Ani;
    
    type
      TForm1 = class(TForm)
        ToolBar1: TToolBar;
        ListView1: TListView;
        PullPaintBox: TPaintBox;
        AniIndicator1: TAniIndicator;
        RefreshTimer: TTimer;
        RefreshLabel: TLabel;
        RefreshImage: TImage;
        FloatAnimation1: TFloatAnimation;
        Label1: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Single);
        procedure ListView1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Single);
        procedure RefreshTimerTimer(Sender: TObject);
      private
        ShowUp, ShowDown: Boolean;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.fmx}
    
    procedure TForm1.FormCreate(Sender: TObject);
    var i: Integer;
        Item1: TListViewItem;
    begin
         for i:=0 to 100 do
         begin
              Item1 := ListView1.Items.Add;
              Item1.Text := i.ToString;
         end;
         ShowUp   := False;
         ShowDown := False;
    end;
    
    procedure TForm1.ListView1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Single);
    begin
         if not AniIndicator1.Visible then
         begin
              RefreshLabel.Visible := True;
              if ListView1.ScrollViewPos < -80 then
              begin
                   RefreshLabel.Text := '放开后可更新';
    
                   RefreshImage.Visible := True;
                   if not ShowUp then
                   begin
                        ShowUp := True;
                        FloatAnimation1.StartValue := 360;
                        FloatAnimation1.StopValue  := 180;
                        FloatAnimation1.Start;
                   end;
              end
              else
              if ListView1.ScrollViewPos < -40 then
              begin
                   RefreshLabel.Text := '下拉可更新';
    
                   RefreshImage.Visible := True;
                   if not ShowDown then
                   begin
                        ShowDown := True;
                        FloatAnimation1.StartValue := 180;
                        FloatAnimation1.StopValue  := 360;
                        FloatAnimation1.Start;
                   end;
              end
              else
              begin
                   RefreshLabel.Text := '';
                   RefreshImage.Visible := False;
              end;
         end;
    end;
    
    procedure TForm1.ListView1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Single);
    begin
         if RefreshLabel.Visible then
         begin
              RefreshLabel.Visible := False;
    
              // 开始更新
              AniIndicator1.Visible := True;
              AniIndicator1.Enabled := True;
    
              RefreshTimer.Enabled := True;
         end;
    end;
    
    procedure TForm1.RefreshTimerTimer(Sender: TObject);
    begin
         // 结束更新
         RefreshTimer.Enabled  := False;
    
         AniIndicator1.Enabled := False;
         AniIndicator1.Visible := False;
    
         ShowUp   := False;
         ShowDown := False;
    end;
    
    end.
  • 相关阅读:
    SQL2014还原到2008
    SQL SERVER2014 安装 Error code 0x858C001B.
    c++builder XE7 C++11 C++0x 新语法
    c++Builder XE6 MD5 加密算法 BASE64 URL 编码
    手机新功能
    xe fmx 怎么改变button颜色
    XE6 任务栏 控件
    js里面return 和 return false的区别
    web.xml的contextConfigLocation作用及自动加载applicationContext.xml
    mybatis-config.xml配置
  • 原文地址:https://www.cnblogs.com/onechen/p/3627967.html
Copyright © 2011-2022 走看看