Android Question Gravity.FILL question

clooney48

Active Member
Licensed User
Longtime User
Hi!
I don´t get it! I want to fit the image which I load from "/100Media/" on the screen. It is always too large. What is wrong with this code?
B4X:
  Dim Bitmap1 As Bitmap
   
   TouchImageView1.Initialize("TouchImageView1")
   Activity.AddView(TouchImageView1, 0, 0, 100%x, 100%y)
   
   TouchImageView1.MinScale=0.5     
   TouchImageView1.MaxScale=1.5       
   TouchImageView1.TranslatePadding=64dip   

   Bitmap1.Initialize(File.DirRootExternal & "/DCIM" & "/100Media/", DBUpdate.vbild)
   TouchImageView1.SetBitmap(Bitmap1)
   TouchImageView1.Gravity = Gravity.FILL
   SourceImageRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height)
   TouchImageViewRect.Initialize(0, 0, TouchImageView1.Width, TouchImageView1.Height)
And how does it work for an image in landscape mode??
 
Last edited:

bgsoft

Well-Known Member
Licensed User
Longtime User
Hello

Add this:
B4X:
TouchImageView1.ScaleSrcRectToDestRect(SourceImageRect, TouchImageViewRect, "CENTER")

below the:
TouchImageViewRect.Initialize(0, 0, TouchImageView1.Width, TouchImageView1.Height)

If you want the image weighs less memory, change this:

Bitmap1.Initialize(File.DirRootExternal & "/DCIM" & "/100Media/", DBUpdate.vbild)
for this:



B4X:
' plays with the 100%x and 100%y to put it to your liking.  I have put 300

Bitmap1.InitializeSample (File.DirRootExternal & "/DCIM" & "/100Media/", DBUpdate.vbild,100%x,100%y)


regards
 
Upvote 0

clooney48

Active Member
Licensed User
Longtime User
Hi!

Thanks, but unfortunately doesn´t work.
And what is also funny: when I use 72% for x and y in TouchImageView1 the image is much smaller than the view, when I use 74 % it is much bigger!?

best regards
 
Last edited:
Upvote 0

clooney48

Active Member
Licensed User
Longtime User
Hi bgsoft!

It works now with your changes after I removed this line:
B4X:
TouchImageView1.Gravity = Gravity.FILL
Thank you!
 
Upvote 0
Top