java - Determine size of whitespace in ImageView -


I have a floor plan, which is centered in an ImageView. The aspect ratio of the image is preserved, so there is some space on either side of the image (shown in red color).

How can I determine the width of this red space in pixels or DPs?

Enter image details here

  & lt ; RelativeLayout xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: Tools = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "Match_parent" Android: paddingLeft = "@ dimen / activity_horizontal_margin" Android: paddingRight = "@ dimen / activity_horizontal_margin" Android: paddingTop = "@ dimen / activity_vertical_margin" Android: paddingBottom = "@ dimen / activity_vertical_margin" tool: reference = "MyActivity "Android: Background =" @color / red "Android: orientation =" vertical "& gt; & Lt; Android: layout_height = "wrap_content" on Android: src = "@ drawable / floor_plan2" Android: adjustViewBounds = "true" Android: layout_toStartOf = "@ + Id / locateMe "Android: layout_alignParentTop =" true "Android: layout_alignParentStart =" true "android: layout_alignParentEnd =" true "/>  

Let me note that margins have been set to 0dp in the dimens.xml file.

itemprop = "text">

After this, see only the calculation:

  integer originalImgWidth = bitmap.getWidth (); Int original ImgHeight = bitmap.getHeight (); Float scale = screen heights * 1f / original impact light; // When your IMG will screen the screen, then the margin size = (Screenshuge - (original IMGWIDTH * scale)) / 2;  

Note that the size can be negative if the image is larger than the screen is horizontal ^^

See how to get a bitmap

See how to get a screen size


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -