大致思路: 就是放两个文字,一个在显示区域,一个在显示区域的下面,大小都和显示区域相同。让后通过qml的动画更改两个Text的y属性。
自己做的时候,一直出现两个文字都是显示不管在不在显示区域。后来发现有个属性:clip 设置为true后就可以。clip裁剪,到现在。总算是明白它的意思了。
动画要用以个串行动画里面包含一个并行的动画和一个直接的y变化的动画。不过,直接用一个并行的动画执行貌似也没有什么问题。
Item {
id: root
width: 100
height: 80
clip: true
Column{
Text{
id: text1
text: "1111111111"
width: root.width
height: root.height
font.pixelSize: 40
}
Text{
id: text2
text: "2222222222"
width: root.width
height: root.height
font.pixelSize: 40
}
}
SequentialAnimation {
id: animation
running: false
ParallelAnimation{
NumberAnimation{
target: getObj(1)
property: "y"
from: 0
to: -root.height
duration: 3000
}
NumberAnimation{
target: getObj(0)
property: "y"
from: root.height
to: 0
duration: 3000
}
}
NumberAnimation{
target: getObj(1)
property: "y"
to: root.height
duration: 0
}
}
property int type: 1
function scrooll() {
animation.running = true;
if(type === 1) {
type = 0;
} else {
type = 1;
}
}
function getObj(data) {
if(data === type) {
return text1;
} else {
return text2;
}
}
}