Android의 VisualElement 권한 상승

이 Android 플랫폼별은 API 21 이상을 대상으로 하는 애플리케이션에서 시각적 요소의 권한 상승 또는 Z 순서를 제어하는 데 사용됩니다. 시각적 요소의 권한 상승은 그리기 순서를 결정하며 Z 값이 더 높은 시각적 요소는 Z 값이 낮은 시각적 요소를 차단합니다. 연결된 속성을 boolean 값으로 설정 VisualElement.Elevation 하여 XAML에서 사용합니다.

<ContentPage ...
             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
             Title="Elevation">
    <StackLayout>
        <Grid>
            <Button Text="Button Beneath BoxView" />
            <BoxView Color="Red" Opacity="0.2" HeightRequest="50" />
        </Grid>        
        <Grid Margin="0,20,0,0">
            <Button Text="Button Above BoxView - Click Me" android:VisualElement.Elevation="10"/>
            <BoxView Color="Red" Opacity="0.2" HeightRequest="50" />
        </Grid>
    </StackLayout>
</ContentPage>

또는 흐름 API를 사용하여 C#에서 사용할 수 있습니다.

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
...

public class AndroidElevationPageCS : ContentPage
{
    public AndroidElevationPageCS()
    {
        ...
        var aboveButton = new Button { Text = "Button Above BoxView - Click Me" };
        aboveButton.On<Android>().SetElevation(10);

        Content = new StackLayout
        {
            Children =
            {
                new Grid
                {
                    Children =
                    {
                        new Button { Text = "Button Beneath BoxView" },
                        new BoxView { Color = Color.Red, Opacity = 0.2, HeightRequest = 50 }
                    }
                },
                new Grid
                {
                    Margin = new Thickness(0,20,0,0),
                    Children =
                    {
                        aboveButton,
                        new BoxView { Color = Color.Red, Opacity = 0.2, HeightRequest = 50 }
                    }
                }
            }
        };
    }
}

이 메서드는 Button.On<Android> 이 플랫폼별이 Android에서만 실행되도록 지정합니다. VisualElement.SetElevation 네임스페이 Xamarin.Forms.PlatformConfiguration.AndroidSpecific 스의 메서드는 시각적 요소의 권한 상승을 nullablefloat로 설정하는 데 사용됩니다. 또한 이 메서드를 VisualElement.GetElevation 사용하여 시각적 요소의 상승 값을 검색할 수 있습니다.

그 결과 Z 값이 높은 시각적 요소가 Z 값이 낮은 시각적 요소를 폐색할 수 있도록 시각적 요소의 상승이 제어될 수 있습니다. 따라서 이 예제에서 두 번째 Button 값은 상승 값이 BoxView 높기 때문에 위의 렌더링됩니다.

VisualElement 권한 상승 스크린샷