alexrainman / CarouselView

CarouselView control for Xamarin Forms
MIT License
436 stars 176 forks source link

CarouselView doesn't render with AbsoluteLayout on Android #38

Closed jerone closed 7 years ago

jerone commented 7 years ago

We have successfully implemented the CarouselView in our application. When trying to put a few buttons for navigation on top of the CarouselView (background red), it got weird. We use AbsoluteLayout, because at one point we'll use a transparent background so the buttons will hover over the carousel content. However it won't render on Android, while it does work on iOS (see screenshot below).

The XAML looks like:

    <AbsoluteLayout BackgroundColor="Yellow" VerticalOptions="Fill">
        <StackLayout BackgroundColor="Blue" VerticalOptions="FillAndExpand">
            <controls:CarouselViewControl
                x:Name="IntroCarousel"
                ItemTemplate="{StaticResource myTemplateSelector}"
                ItemsSource="{Binding Pages}"
                Position="0" />
        </StackLayout>
        <StackLayout
            AbsoluteLayout.LayoutBounds="1,1,.5,1" 
            AbsoluteLayout.LayoutFlags="All"
            BackgroundColor="Red"
            Orientation="Horizontal"
            VerticalOptions="End">
            <Button
                x:Name="prevBtn"
                IsVisible="false"
                Style="{StaticResource IntroPreviousBtnStyle}"
                Text="Previous" />
            <Button
                x:Name="nextBtn"
                Style="{StaticResource IntroNextBtnStyle}"
                Text="Next" />
        </StackLayout>
    </AbsoluteLayout>

Current situation

Screenshot of our app on iOS (working): ios

Screenshot of our app on Android (not working): android

Expected situation

So we expected to see no yellow background and the first item of the CarouselView to be visible (purple).

Is this a bug with CarouselView?


XF 2.3.3.168 CarouselView 2.5.1

jerone commented 7 years ago

So it appeared to be some inconsistency between Xamarin.iOS and Xamarin.Android, because the following XAML code works:

    <AbsoluteLayout BackgroundColor="Yellow"
                    HorizontalOptions="Fill"
                    VerticalOptions="Fill">
        <StackLayout AbsoluteLayout.LayoutBounds="0,0,1,1"
                     AbsoluteLayout.LayoutFlags="All"
                     BackgroundColor="Blue"
                     HorizontalOptions="FillAndExpand"
                     VerticalOptions="FillAndExpand">
            <controls:CarouselViewControl x:Name="IntroCarousel"
                                          HorizontalOptions="FillAndExpand"
                                          ItemTemplate="{StaticResource myTemplateSelector}"
                                          ItemsSource="{Binding Pages}"
                                          Position="0"
                                          VerticalOptions="FillAndExpand" />
        </StackLayout>
        <StackLayout AbsoluteLayout.LayoutBounds="1,1,0.9,1"
                     AbsoluteLayout.LayoutFlags="All"
                     BackgroundColor="Red"
                     Orientation="Horizontal"
                     VerticalOptions="End">
            <Button x:Name="prevBtn"
                    IsVisible="false"
                    Style="{StaticResource IntroPreviousBtnStyle}"
                    Text="Previous" />
            <Button x:Name="nextBtn"
                    Style="{StaticResource IntroNextBtnStyle}"
                    Text="Next" />
        </StackLayout>

Thanks for the great control.

alexrainman commented 7 years ago

Did you solved this?

jerone commented 7 years ago

@alexrainman commented on 2 dec. 2016 18:26 CET:

Did you solved this?

Yeah, see code above. The trick was to use the LayoutBounds on both StackLayout.

alexrainman commented 7 years ago

Yes, Forms has some problems in Android.

jerone commented 7 years ago

I'm not sure which one was correct (iOS or Android), but still weird that they behave differently. 😞

alexrainman commented 7 years ago

If my work is helping you, please help me back: https://xamarinhq.wufoo.com/forms/nominate-a-xamarin-mvp/

alexrainman commented 7 years ago

This is what i have done that is community visible: