<Slider name="" bounceInitSpeed="" bounceAcceleration="" keyPoint="" always=""> <StartPoint x="" y="" w="" h=""> <NormalState> <Image x="" y="" src=""/> </NormalState> </StartPoint> <EndPoint x="" y="" w="" h=""> <PressedState> <Image x="" y="" src=""/> </PressedState> <Path x="" y=""> <Position x="" y=""/> <Position x="" y=""/> </Path> </EndPoint> </Slider>
参 数 | 类 型 | 选 项 | 注 释 |
|---|---|---|---|
name | 字符串 | 必填 | 滑动组件的名称 |
bounceInitSpeed | 数值 | 选填 | 回弹动画的初始速度(距离单位为像素,时间单位为秒),支持表达式,最小100,默认值为0 |
bounceAcceleration | 数值 | 选填 | 回弹动画的加速度(距离单位为像素,时间单位为秒),支持表达式,最小10,默认值为0 |
keyPoint | 数值 | 选填 | 回弹点,可实现回弹多次的效果;默认值“0,0”即触发完回到开始效果。另外:如“0,0.7,0,0.5,0,0.2,0” 表示逐渐回弹到原点 |
always | 字符串 | 选填 | 当always的值变为true或1时,表示仅仅只显示这个滑块,其他的滑块全部隐藏 ;当always的值变为false或0时,表示所有的滑块全部显示出来 |
StartPoint | 字符串 | 必填 | 起始点标签,包括了x, y, weight, height坐标长宽以及Normal、Pressed、reached等状态的View集合和声音文件,也包括了Intent相关操作。注意:每个Slider仅能包括一个StartPoint |
EndPoint | 字符串 | 必填 | 结束点标签,其与起始点标签相同,但是Slider中可以有多个EndPoint |
参 数 | 类 型 | 选 项 | 注 释 |
|---|---|---|---|
x | 数值 | 必填 | 起始点相对于屏幕左上角的x坐标 |
y | 数值 | 必填 | 起始点相对于屏幕左上角的y坐标 |
w | 数值 | 选填 | 起始点响应区域的大小,宽 |
h | 数值 | 选填 | 起始点响应区域的大小,高 |
NormalState | 字符串 | 选填 | 正常状态标签,表示在非触摸时的状态 |
PressedState | 字符串 | 选填 | 按下状态标签,表示在点击区域按下开始触发的状态信息 |
ReachedState | 字符串 | 选填 | 到达状态标签,表示到达目标区域时的状态信息 |
Path | 字符串 | 选填 | 定义了Slider滑动允许的范围,滑动的范围位于Position的连线上面,Path中给予了Position一个基础值,可以简单的认为是从Path定义的x加上Position的x,Path的y加上Position的y的两个Position之间的连线 |
normalSound | 字符串 | 选填 | 普通状态下播放的音效 |
pressedSound | 字符串 | 选填 | 解锁控件在press状态播放的音效 |
示例一:Slider起始点:起始点中包含的元素都会跟随当前操作的拖动移动位置。三个状态都可以不指定,可以使用变量来改变其他界面元素状态来表示触发过程。
<StartPoint x="30" y="120" w="90" h="90" normalSound="sound_normal.mp3" pressedSound="sound_normal.mp3"> <!--正常状态,可以包含若干元素--> <NormalState> <Image/> //从其他状态切换到NormalState时,触发该Trigger <Trigger> <Command target="test_trigger.visibility" value="false"/> </Trigger> </NormalState> <!--在点击区域按下,表示开始触发操作,拖动,隐藏其他状态元素,显示这些元素--> <PressedState> <Image/>//从其他状态切换到PressedState时,触发该Trigger <Trigger> <Command target="test_trigger.visibility" value="true"/> </Trigger> </PressedState> <!--达到触发目标后,隐藏其他元素,显示这些元素--> <ReachedState> <Image/> //从其他状态切换到ReachedState时,触发该Trigger <Trigger> <SoundCommand sound="reached.mp3" volume="1"/> </Trigger> </ReachedState> </StartPoint>
示例二:Slider目标点:当起始点的x,y点落入EndPoint目标区域矩形时,达到触发位置,此时松开手指即可以有mp3音乐播放并执行Intent中指定的打开相机动作。
<EndPoint x="300" y="400" w="90" h="90" reachedSound="sound_reached.mp3"> <!--Slider执行的动作,可以指定不同的IntentCommand--> <IntentCommand action="android.intent.action.MAIN" package="com.huawei.camera" class="com.huawei.camera"/> </EndPoint>
示例三:Slider,其中包括了一个StartPoint和一个EndPoint, 回弹的初速度为2000,加速度为1000。起始点的横坐标为30,纵坐标由表达式确定的屏幕高度-120,宽度90,高度90,其中NormalState显示一张图片;同理EndPoint的坐标解释同上,在PressedState显示另一张图片,同时在EndPoint包括了解锁路径;
Path标签定义了EndPoint可以移动的范围,当手指丛EndPoint往左滑的时候其坐标为 x=30 y = #screen_height-120,当往右滑的距离超过了 360 – 30时,其坐标为x = 360 y = #screen_height-120,而在往右滑距离在0-330中间值得时候,其x = 30 + delaX, y = #screen_height-120。
<Slider name="slider" bounceInitSpeed="2000" bounceAcceleration="1000"> <StartPoint x="30" y="#screen_height-120" w="90" h="90"> <NormalState> <Image x="30" y="#screen_height-120" src="unlock_button.png"></Image> </NormalState> </StartPoint> <EndPoint x="360" y="#screen_height-120" w="90" h="90"> <PressedState> <Image x="360" y="#screen_height-120" src="unlock_target.png"></Image> </PressedState> <Path x="0" y="#screen_height-120"> <Position x="30" y="0"/> <Position x="360" y="0"/> </Path> </EndPoint> </Slider>