M MikieK Member Licensed User Longtime User Dec 4, 2011 #1 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: Code: 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:
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: Code: 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:
Erel B4X founder Staff member Licensed User Longtime User Dec 5, 2011 #2 An example of centering a view is available here: properties - Any way to center a view? - Stack Overflow Upvote 0
An example of centering a view is available here: properties - Any way to center a view? - Stack Overflow
M MikieK Member Licensed User Longtime User Dec 5, 2011 #3 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
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.
M MikieK Member Licensed User Longtime User Dec 6, 2011 #4 Here's what the above is refering to: Boshack Dragon Fly It doesn't include animations, as I couldn't get them to work. Upvote 0
Here's what the above is refering to: Boshack Dragon Fly It doesn't include animations, as I couldn't get them to work.
M MikieK Member Licensed User Longtime User Dec 6, 2011 #5 Dip Pixels = dip * Density according to this:Supporting Multiple Screens | Android Developers so 50%x/Density should equal activity.width/2 Assuming my device is in full screen, why doesn't the above statement work? Upvote 0
Dip Pixels = dip * Density according to this:Supporting Multiple Screens | Android Developers so 50%x/Density should equal activity.width/2 Assuming my device is in full screen, why doesn't the above statement work?
Erel B4X founder Staff member Licensed User Longtime User Dec 6, 2011 #6 50%x = activity.width / 2 Upvote 0
M MikieK Member Licensed User Longtime User Dec 6, 2011 #7 so does 5%x = .05*activity.width? and if so, why didn't my previous code work? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Dec 6, 2011 #8 5%x = .05*activity.width Click to expand... Yes. I do not understand your code. Upvote 0
M MikieK Member Licensed User Longtime User Dec 6, 2011 #9 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
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:
klaus Expert Licensed User Longtime User Dec 6, 2011 #10 so 50%x/Density should equal activity.width/2 Click to expand... No, this is not true ! Activity.Width already takes into account the density ! Have a look in your other post here: Best regards. Upvote 0
so 50%x/Density should equal activity.width/2 Click to expand... No, this is not true ! Activity.Width already takes into account the density ! Have a look in your other post here: Best regards.