在滚动型的顶部的按钮显示不出来(Button on top of the Scrollview do

2019-11-04 05:12发布

我有这样的事,到目前为止我的看法:

   public StackLayout OffersSlideViewCarouselChild(Offer offer)
{
    Image productImage = new Image
    {
        Source = ImageSource.FromUri(new Uri(offer.Image.Replace("https://", "http://"))),
        HeightRequest = 270, 
        WidthRequest = 270,
        Aspect = Aspect.AspectFit
    };

    var topStackLayout = new StackLayout
    {
        Spacing = 0

    };
    topStackLayout.Children.Add(productImage);

    StackLayout contentStackLayout = new StackLayout
    {
        Spacing = 0,
        Padding = new Thickness(5, 10, 5, 10),
        Orientation = StackOrientation.Vertical
    };
    var savedBtn = SavedButtonLayout(offer.IsSelected, offer.Id);
    var redeemBtn = RedeemBtnLayout(offer.Id);
    var timeRemainingLabel = TimeRemainingLayout(offer, offer.Id);


    contentStackLayout.Children.Add(new UILabel(16) {
        Text = offer.ProductName,
        TextColor = ColorHelper.FromHex(CoreTheme.COLOR_OFFERCELL_PRODUCT_TEXT),
        FontFamily = CoreTheme.FONT_FAMILY_DEFAULT_BOLD,
        WidthRequest = DeviceDisplaySettings.defaultwidth,
        VerticalTextAlignment = TextAlignment.Center
});

    contentStackLayout.Children.Add(new UILabel(14)
    {
        Text = offer.Headline,
        TextColor = ColorHelper.FromHex(CoreTheme.COLOR_OFFERCELL_PRODUCT_TEXT),
        FontFamily = CoreTheme.FONT_FAMILY_DEFAULT_BOLD,
        WidthRequest = DeviceDisplaySettings.defaultwidth,
        VerticalTextAlignment = TextAlignment.Center
    });

    contentStackLayout.Children.Add(new UILabel(14) {
        Text = offer.LongRewardsMessage,
        TextColor = ColorHelper.FromHex(CoreTheme.COLOR_DEAL_PAGE_LONG_REWARD_MESSAGE_RED),
        FontFamily = CoreTheme.FONT_FAMILY_DEFAULT_BOLD,
        WidthRequest = DeviceDisplaySettings.defaultwidth,
        VerticalTextAlignment = TextAlignment.Center
    });

    if (!string.IsNullOrEmpty(offer.PowerMessage)) {
        var htmlText = string.Format("<html><body style='color:#9b9b9b'>{0}</body></html>", offer.PowerMessage.Replace(@"\", string.Empty));

        var browser = new WebView() {
            //HeightRequest = (DeviceDisplaySettings.defaultheight > 600) ? 500 : 400,
            HeightRequest = 800,
            Source = new HtmlWebViewSource() { Html = htmlText },
        };
        browser.Navigating += OnNavigating;

        contentStackLayout.Children.Add(browser);
    }

    var nestedStackLayout = new StackLayout()
    {
        VerticalOptions = LayoutOptions.FillAndExpand
    };

    nestedStackLayout.Children.Add(topStackLayout);
    nestedStackLayout.Children.Add(timeRemainingLabel);
    nestedStackLayout.Children.Add(contentStackLayout);

    var mainScrollView = new ScrollView()
    {
        Padding = new Thickness(0, 0, 0, 10),
        VerticalOptions = LayoutOptions.FillAndExpand,
        Orientation = ScrollOrientation.Vertical,
        Content = nestedStackLayout
    };

    var mainStackLayout = new StackLayout()
    {
        Spacing = 5,
        Padding = new Thickness(0, 0, 0, 0),
        VerticalOptions = LayoutOptions.Fill,
        HorizontalOptions = LayoutOptions.Fill,
        Orientation = StackOrientation.Vertical,
        Children = { savedBtn, mainScrollView, redeemBtn }

    };

    return mainStackLayout;
}

private StackLayout SavedButtonLayout(bool isSelected, int offerid)
{
    int buttonsToShow = 2;
    bool displaySaveButton = true;

    if (IsPremisesOffer (offerid)) {
        buttonsToShow = 3;
        displaySaveButton = false;

    }

    btnShare = new UIFieldDefinition(_pageFieldDefinition.ShareButtonDefinition); 
    btnShare.Text = "SHARE";
    btnShare.ClassId = offerid.ToString();
    btnShare.WidthRequest = (DeviceDisplaySettings.defaultwidth / buttonsToShow) - 40;
    btnShare.BackgroundColor = Color.FromRgb(167, 188, 33);
    btnShare.VerticalContentAlignment = TextAlignment.Center;
    btnShare.HandleClick(btnShare_Clicked);


    btnSave = new UIFieldDefinition(_pageFieldDefinition.SaveButtonDefinition);
    btnSave.Text = isSelected ? "UNSAVE" : "SAVE";
    btnSave.ClassId = offerid.ToString();
    btnSave.WidthRequest = (DeviceDisplaySettings.defaultwidth / buttonsToShow) - 40;
    btnSave.BackgroundColor = Color.FromRgb(167, 188, 33);
    btnSave.VerticalContentAlignment = TextAlignment.Center;
    btnSave.HandleClick(btnSave_Clicked);

    rl = new StackLayout {
        Spacing = 10,
        Orientation = StackOrientation.Horizontal,
        BackgroundColor = Color.FromRgb(196, 221, 57),
        Padding = new Thickness(40, 5, 5, 5),
        WidthRequest = DeviceDisplaySettings.defaultwidth
    };

    rl.Children.Add(btnShare);
    if (displaySaveButton) rl.Children.Add(btnSave);

    return rl;
}

public UIFieldDefinition RedeemBtnLayout(int offerid)
{
    int buttonsToShow = 1;

    btnRedeem = new UIFieldDefinition(_pageFieldDefinition.RedeemButtonDefinition);
    btnRedeem.Text = "REDEEM NOW";
    btnRedeem.ClassId = offerid.ToString();
    btnRedeem.WidthRequest = (DeviceDisplaySettings.defaultwidth / buttonsToShow) - 10;
//  btnRedeem.HorizontalOptions = LayoutOptions.FillAndExpand;
//  btnRedeem.VerticalOptions = LayoutOptions.EndAndExpand;
    btnRedeem.HandleClick(btnRedeem_Clicked);



    return btnRedeem;
}

然而,我注意到的是,兑换按钮,甚至没有在视图中显示(这应该被固定在底部)。

滚动视图工作,但是BUTTOM丢失。 为什么?

请让我知道如果你需要进一步的代码的详细信息。

Answer 1:

从上述评论搬到这里。 有从我可以告诉两个不同的问题,据我所知,是不相关的:

  1. 在WebView中,嵌套了滚动里面,是不是大到足以充分显示内容。
  2. 其被认为是在屏幕的底部的按钮不显示。

对于他们两人来说,答案可能是你如何设置HeightRequest。 已经有很多我自己的建议和其他评论者改变或摆脱一些HeightRequest设置,我不知道您的源代码的当前状态。 因此,假如那些仍然存在:

  1. 为了解决该问题,网页视图,请阅读我怎样才能在Xamarin的形式添加HTML到Stacklayout滚动型里面? 。 这将让你找出使用权HeightRequest。 简短的答案是,这取决于你希望发生什么,你可能需要一个定制的渲染器。 需要注意的是HeightRequest对的WebView不会影响滚动型之外的任何布局。

  2. 为了解决没有出现按钮的问题,摆脱HeightRequest上了滚动设置,并在创建SavedButtonLayout在StackLayout的VerticalOptions的。

我假设你做的实验表明以上,以确保如果放在了滚动前redeemBtn将呈现,而且它显示出来即可。 如果没有,你首先需要解决这个问题。



Answer 2:

如果您已经通过更改HeightRequest“固定”这个那么你的真正的问题是所有的意见和布局的固定像素大小,我建议你不要使用固定的像素大小不同的屏幕分辨率,这将是一个更大的问题之后,有什么你可以做的就是屏幕尺寸和做数学题,以适应该视图的所有元素,一个办法让屏幕的宽度和高度上OnSizeChanged的活动Pages (像ContentPage),是这样的:

SizeChanged += SizeChanged;
void SizeChanged (object sender, EventArgs e)
{
    Layout.WidthRequest = Width * 0.3;
    Layout.HeightRequest = Height * 0.35;
}


Answer 3:

您的布局相当繁忙。 一些东西:

  1. 设置VerticalOptionsEndAndExpandredeemBtn
  2. 设置VerticalOptionsStartAndExpandsavedBtn
  3. 设置VerticalOptionsFillmainScrollView
  4. 设置VerticalOptionsFillAndExpandmainRelLayout
  5. VerticalOptionsHorizontalOptionsFillmainStackLayout

我认为,这将让你到你想去的地方。

包括“扩展”的选项将增长的元件,以适应其内容物的所需的高度。



文章来源: Button on top of the Scrollview does not show up