mohammad anouti
mohammad anouti

Reputation: 171

Frame animation from outside screen and translateto inside screen

I'm new to animation with Xamarin Forms, I have a frame that I need to place it outside the screen like this:

outside

The small frame is outside the device's screen

inside

The small frame now inside the device screen

My problem is I need to know how I can place the frame like that (outside the screen) from the start, and how to know the width and the height of every device so I can use the TranslateTo() method to translate the frame to the exact same position for every device.

Thanks in advance

Upvotes: 0

Views: 229

Answers (2)

Jessie Zhang -MSFT
Jessie Zhang -MSFT

Reputation: 13919

You can use Xamarin.Essentials NuGet pakage to achieve this. And there is a useful class DeviceDisplay in there that should be helpful for you.

The documentation can be found here.

Usage example:

        // Get Metrics
        var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;

        // Orientation (Landscape, Portrait, Square, Unknown)
        var orientation = mainDisplayInfo.Orientation;

        // Rotation (0, 90, 180, 270)
        var rotation = mainDisplayInfo.Rotation;

        // Width (in pixels)
        var width = mainDisplayInfo.Width;

        // Height (in pixels)
        var height = mainDisplayInfo.Height;

        // Screen density
        var density = mainDisplayInfo.Density;

Upvotes: 1

Akshar M.
Akshar M.

Reputation: 146

You can try this from your .cs page

  • Application.Current.MainPage.Width
  • Application.Current.MainPage.Height

Upvotes: 1

Related Questions