How to fit image for all resolutions ?

Shay Wilner 1,746 Reputation points
2021-12-06T09:19:52.277+00:00

Hello
I drew a chess board by dividing the screen width into 8 parts.
I had an image view loaded with an image fit to the square for the chessboard.
It works but only for one resolution but if I run the application using another emulator with another resolution the image exceed from the square.
The image is stored in in the asset folder.
Thanks

Developer technologies | .NET | Xamarin
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-12-08T02:40:30.643+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Try setting the height of the Queen chesses according to the screen size programmatically.

    Here is the sample code, you could refer to it.

       int displayWidth = WindowManager.DefaultDisplay.Width;  
       var the_queen = ...;  
         
       var layoutParameter = the_queen.LayoutParameters;  
       layoutParameter.Height = displayWidth / 8;  
       the_queen.LayoutParameters = layoutParameter;  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.