有没有办法从两侧以编程方式为按钮的宽度设置动画 [英] Is there a way to animate the width of button programmatically from both sides
本文介绍了有没有办法从两侧以编程方式为按钮的宽度设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够从两侧动态调整按钮的大小,现在我可以从右侧向左侧进行调整.
I want to be able to resize animatedly the button from both sides for now I was able to do it from one side right to left.
代码 ->
double Height = Button1.Height;
bool x = await Button1.LayoutTo(new Rectangle(new Point(Button1.X, Button1.Y), new Size(150, Height)), 1200,Easing.Linear);
按钮 ->
<StackLayout VerticalOptions="Center">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button x:Name="Button1" Grid.Row="0" Clicked="Button1_Clicked" BorderRadius="20" HorizontalOptions="CenterAndExpand" WidthRequest="1500" />
<!--<ActivityIndicator Grid.Row="1" IsRunning="true" ></ActivityIndicator>-->
</Grid>
</StackLayout>
(动画前)->
(动画后)->
(我想要)->
推荐答案
如果您只打算调整大小,请使用 ScaleXTo
并将 AnchorX
设置为 0.5(默认).
If Resize is all you intend to do, use ScaleXTo
with AnchorX
set to 0.5(default).
在 XAMl 中设置 AnchorX:
Set AnchorX in XAMl:
<Button
x:Name="Button1"
Grid.Row="0"
Clicked="Button1_Clicked"
BorderRadius="20"
AnchorX="0.5"
HorizontalOptions="CenterAndExpand"
WidthRequest="1500" />
使用 ScaleXTocs
void Button1_Clicked(System.Object sender, System.EventArgs e)
{
if (Button1.ScaleX < 1)
{
Button1.ScaleXTo(1);
}
else
{
Button1.ScaleXTo(0.5);
}
}
如果需要更多信息,请试一试并发表评论.希望有帮助.
Give it a whirl and comment if further info is needed. Hope it helps.
这篇关于有没有办法从两侧以编程方式为按钮的宽度设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文