【发布时间】:2017-01-04 03:18:29
【问题描述】:
我试图让一排按钮根据是否添加或删除其他按钮来增长和缩小。 FlexboxLayout 似乎最适合这项工作,但我似乎不知道如何解决这个问题,除了手动操作一段时间内的宽度百分比。
我想我可以在它们上设置flexGrow,然后使用带有visibility: collapse 的类来从根本上删除按钮。 (然后在恢复正常时反转。)这有效,但变化是瞬间的。我想要某种挤压/拉伸动画。
我尝试使用动画,将比例缩小到 0,如下所示。虽然按钮看起来缩小了,但它只是向自身中心收缩,并且仍然保持它所占据的空间(留出一个空隙)。
我在玩这样一个简单的例子:
<FlexboxLayout flexDirection="row">
<Button text="1" width="25%" flexGrow="1"></Button>
<Button text="2" width="25%" id="test-button"></Button>
<Button text="3" width="25%" flexGrow="1"></Button>
<Button text="4" width="25%" flexGrow="1"></Button>
</FlexboxLayout>
我尝试做这样的事情,我想缩小按钮 #2 消失:
let testButton = this.page.getViewById("test-button");
testButton.animate({
scale: { x: 0, y: 1},
duration: 500
});
我也尝试使用关键帧来做到这一点。这似乎没有任何作用。
#test-button {
animation-name: shrink;
animation-duration: 2s;
animation-delay: 1s;
}
@keyframes shrink {
from { width: 25%; }
to { width: 0; }
}
我尝试做类似in this answer here for web pages 提到的事情,但这似乎也没有任何作用。
我设法通过使用setTimeout 手动调整宽度的数据绑定使其工作。但我想知道是否可能有一条不同的路线可能更容易管理?不禁想知道我是否在其他尝试中搞砸了。
【问题讨论】:
标签: nativescript angular2-nativescript