DIP again, sorry!

MikieK

Member
Licensed User
Longtime User
Up until now, I have been using canvas and bitmap, to put info on a screen. I'm extremely used-to quoting dimensions as a percentage of the screen (eg. 50%x)
I just tried to create an image view in the middle of the screen with its child bitmap dimensions:
B4X:
Dim df1 As Bitmap
Dim dfv As ImageView
df1.InitializeSAMPLE(File.DirAssets,"df1.png",10%x,398*10%x/665)
dfv.Initialize("")
activity.AddView(dfv,50%x-5%x,50%y-10%x/df1.Width*df1.height/2,50%x+5%x,50%y+10%x/df1.Width*df1.height/2)
dfv.Bitmap = df1
I was expecting the imageview to be in the middle of the screen, but it obviously wasn't (it was in the bottom right), and it wasn't the size of the df1 bitmap(too big). Dividing the values by density (eg. 50%x/density-5%x /density) comes close, but the imageview is still too big. What am I doing wrong? How do I go from CurrenttoDip?:BangHead::sign0013:
 

MikieK

Member
Licensed User
Longtime User
cheers again. I did search for over 30min, and I had tried to use the activity dimensions. It seems the closest I get is adding the view in the top left corner of the activity (to get similar dimensions to the bitmap it holds) then moving it to a proportion of activity.width or height. DIP is confusing as hell, and I would have steered clear of using imageviews, if there wasnt a noticeble performance increase(and decrease in battery consumption) when moving pngs with transparent areas over another image. I have tried using multiple pannels and canvases (transparent rect to clear area covered) which doesnt work- it fills black not transparent. I have also tried, filling the tarnished area with the background image, clipped to a rect which lags a lot. I tried creating a mutable bitmap and setting it to the activity background. Imageview seems the best option, as it is already optimised, plus,it enables me to slow my game timer down to over 50ms (if I use animations) . I will attach my work so far (if my wife ever lets me back on the laptop) so you know what Im on about.
 
Upvote 0

MikieK

Member
Licensed User
Longtime User
me neither :)


I just got it, I was attempting to addview(view,left,top,right,bottom) as in a rect, rather than addview(view,left,top,width,height). Sorry for wasting your time yet again.

:signOops:
 
Upvote 0
Top