注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[必看][类]带滑动效果的滑动开关(二)  

2014-09-18 13:58:50|  分类: B.类模块 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
类模块SW代码如下

'Class module
Sub Class_Globals
Dim BackImage As Label 
Dim SlideImage As Label

Dim Panel1 As Panel 
Dim Anim1 As Animation 
Dim Anim2 As Animation 
Dim Iscomplete As Boolean 
Dim ObjModule As Object 
Dim ParentEventName As String 
Public SelectState As Boolean 
End Sub

'功能:初始化
Public Sub Initialize(Parent As Panel,vLeft As Int,vTop As Int,vWidth As Int,vHeight As Int,Module As Object,EventName As String)
ObjModule=Module
ParentEventName=EventName
Panel1.Initialize("")
Panel1.Color=Colors.ARGB(0,0,0,0)
Parent.AddView(Panel1,vLeft,vTop,vWidth,vHeight)
BackImage.Initialize("SlideImage")
SlideImage.Initialize("SlideImage")
SelectState=True
SlideImage.Tag="off"
SetPng(BackImage,"off")
SetPng(SlideImage,"h0")

Panel1.AddView(BackImage,0dip,0dip,Panel1.Width,Panel1.Height)
Panel1.AddView(SlideImage,0dip,0dip,Panel1.Height,Panel1.Height)
End Sub

'设置图片背景
Sub SetPng(Control As View, ImageName As String)
Dim r As Reflector
Dim package As String
Dim id As Int
package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
id = r.GetStaticField(package & ".R$drawable", ImageName)
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
Control.Background = r.RunMethod2("getDrawable", id, "java.lang.int")
End Sub

'动画结束
Sub Anim1_AnimationEnd
If SlideImage.Tag="on" Then
SlideImage.Left=Panel1.Width-SlideImage.Width
SelectState=False
Else
SlideImage.Tag="off"
SlideImage.Left=0dip
SelectState=True
End If
If SubExists(ObjModule,ParentEventName & "_SelectState") Then
CallSub2(ObjModule,ParentEventName & "_SelectState",SelectState)
End If
End Sub

'动画结束
Sub Anim2_AnimationEnd
If SlideImage.Tag="on" Then
SetPng(BackImage,"on")
Anim2.InitializeAlpha("Anim2",0,1)
Else
SetPng(BackImage,"off")
Anim2.InitializeAlpha("Anim2",0,1)
End If
Anim2.Duration=250
If Iscomplete=False Then
Iscomplete=True
Anim2.Start(BackImage)
End If
End Sub

'图片被点击
Sub SlideImage_Click
Iscomplete=False
If SlideImage.Tag="off" Then
SlideImage.Tag="on"
Anim1.InitializeTranslate("Anim1",0dip,0dip,Panel1.Width-SlideImage.Width,0dip)
Anim1.Duration=500
Anim1.Start(SlideImage)
Anim2.InitializeAlpha("Anim2",1,0)
Anim2.Duration=250
Anim2.Start(BackImage)
Else
SlideImage.Tag="off"
Anim1.InitializeTranslate("Anim1",0dip,0dip,-SlideImage.left,0dip)
Anim1.Duration=500
Anim1.Start(SlideImage)
Anim2.InitializeAlpha("Anim2",1,0)
Anim2.Duration=250
Anim2.Start(BackImage)
End If
End Sub

'功能:设置开关状态,参数为true时开,false为关
Public Sub SetState(State As Boolean)

If State Then
SlideImage.Tag="on"
Else
SlideImage.Tag="off"
End If
SlideImage_Click
End Sub
  评论这张
 
阅读(240)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017