Xamarin Forms 淡出隐藏?

标签 xamarin xamarin.forms

在我当前的应用程序中,我有一堆按钮可以隐藏或显示它们对应的 stackLayout。
首先,我尝试使用 IsVisble 属性,但这会导致闪烁,
现在我正在使用 LayoutTo() 这也闪烁?

我的代码如下:

async void btnStrike_Clicked(object sender, EventArgs args)
        {
            var layout = this.FindByName<StackLayout>("stkStrikeInfo");
            var rect = new Rectangle(layout.X, layout.Y, layout.Width, layout.Height - layout.Height);
            await layout.LayoutTo(rect, 2500, Easing.Linear);
        }

我想为高度设置动画!

编辑:

我找到了以下一段代码,它从页面中删除了 Stacklayout。
现在的问题是 View 没有更新?

最佳答案

我认为您只需要一个默认动画就会有更好的运气,它将您想要隐藏的布局的高度降低到零。

void btnStrike_Clicked(object sender, EventArgs args)
{
    // get reference to the layout to animate
    var layout = this.FindByName<StackLayout>("stkStrikeInfo");

    // setup information for animation
    Action<double> callback = input => { layout.HeightRequest = input; }; // update the height of the layout with this callback
    double startingHeight = layout.Height; // the layout's height when we begin animation
    double endingHeight = 0; // final desired height of the layout
    uint rate = 16; // pace at which aniation proceeds
    uint length = 1000; // one second animation
    Easing easing = Easing.CubicOut; // There are a couple easing types, just tried this one for effect

    // now start animation with all the setup information
    layout.Animate("invis", callback, startingHeight, endingHeight, rate, length, easing);
}

如果布局已经隐藏并且您想显示它,您将替换
double startingHeight = layout.Height;
double endingHeight = 0;


double startingHeight = 0;
double endingHeight = 55;

55 只是一个任意的高度,如果你想让它回到之前的高度,你可以在隐藏之前将先前的高度保存到一个变量中,并使用保存的高度而不是 55。

关于Xamarin Forms 淡出隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36498306/

相关文章:

android - Xamarin Forms Custom TabbedRenderer 删除 Android 上的 TabLayout

c# - Xamarin.Forms 绑定(bind)指定的转换无效

android - TextView 位于 RelativeLayout 中的按钮后面

c# - 当我旋转 Android 模拟器以将方向更改为横向模式或纵向模式时,不会调用“OnSizeAllocation”

xamarin - 为 Xamarin 创建 Android 绑定(bind)时出现问题

python - 如何在Web服务器中托管python脚本并通过从xamarin应用程序调用API来访问它?

xamarin - Xamarin Studio 中的类型或命名空间名称 'Xamarin' 缺少错误

c# - 异步方法导致应用程序崩溃

ios - Xamarin Forms webview 根本无法在 IOS 上运行

c# - 有没有办法为 Xamarin.Forms.Maps 引脚移动设置动画