c# - 有没有办法从两侧以编程方式为按钮的宽度设置动画
问题描述
我希望能够从两侧动态调整按钮的大小,现在我能够从一侧从右到左做到这一点。
代码 ->
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(默认)。
在 XAMl 中设置 AnchorX:
<Button
x:Name="Button1"
Grid.Row="0"
Clicked="Button1_Clicked"
BorderRadius="20"
AnchorX="0.5"
HorizontalOptions="CenterAndExpand"
WidthRequest="1500" />
在 cs 中使用ScaleXTo
void Button1_Clicked(System.Object sender, System.EventArgs e)
{
if (Button1.ScaleX < 1)
{
Button1.ScaleXTo(1);
}
else
{
Button1.ScaleXTo(0.5);
}
}
如果需要更多信息,请试一试并发表评论。希望能帮助到你。
推荐阅读
- javascript - 最长连续历史问题的问题
- javascript - 关于具有数组高阶函数的正则表达式全局搜索的问题
- python - Flask Python多次重新加载对象
- r - 如何基于检查多个列的多个值有条件地编码新变量
- html - 如何使跨度通过 2 个容器 div
- kubernetes - 列出正在为服务提供服务的 pod
- karate - 空手道:如何在空手道中初始化 RemoteWebDriver
- python - 用神经网络识别钞票,我必须裁剪数据集的图像吗
- javascript - 当我的 Angular 库项目使用“--prod”选项启动时,扩展内置类的方法(通过 JS 的“.prototype”属性)不起作用
- javascript - 首先通过节点后端传递所有http请求和React Routes进行会话验证,然后返回路径