Android Question Loading the same picture but with different result (other subpart of image)

DonManfred

Expert
Licensed User
Longtime User
code to fill the Top-images:

B4X:
  For i = 0 To NewsImages.Size-1
        Dim imgtop As ImageView
        imgtop.Initialize("imgtop")
        imgtop.Bitmap = LoadBitmapSample(File.DirDefaultExternal,Main.pathimages&NewsImages.Get(i),110dip,130dip)
        imgtop.Tag = NewsImages.Get(i)
    hsv.Panel.AddView(imgtop, itemSize * i, 0, 210dip, hsv.Panel.Height)
  Next

code to fill the images in the CLV at bottom:

B4X:
ImageView1.Bitmap = LoadBitmapSample(File.DirDefaultExternal,Main.pathimages&filename,110dip,130dip)
ImageView1.Tag = id

The imageview in on a panel which is loaded with panel.loadlayout

Imageview001.png



The images in bottom are OK. But the image in top-horizontal-scrollview are somewhat "only a part of the image"...

I don´t know where my problem is. Any helpful tip would be appreciated :)
 

LucaMs

Expert
Licensed User
Longtime User
I'm not sure I understood.

Even if you used LoadBitmapSample ... 110dip, 130dip for both cases, you get a different result, right?

It could be for one of two reasons:

1) the gravity of the imageview
2) the scrollview is resized

Klaus will help you more ;)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Do i have to SET an Gravity on imageviews? What command should i use to set the right Gravity?

The HSV (HorizontalScrollView) is only set once to a special size.

B4X:
    itemSize = 220dip
  hsv.Panel.Width = (itemSize * NewsImages.Size)+50dip

  For i = 0 To NewsImages.Size-1
        Dim imgtop As ImageView
        imgtop.Initialize("imgtop")
        imgtop.Bitmap = LoadBitmapSample(File.DirDefaultExternal,Main.pathimages&NewsImages.Get(i),110dip,130dip)
        imgtop.Tag = NewsImages.Get(i)
    hsv.Panel.AddView(imgtop, itemSize * i, 0, 210dip, hsv.Panel.Height)
  Next

After that code the size of hsv do not change
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the Designer the Gravity of an ImageView is Gravity.Fill by default, I don't know what the default gravity is when the ImageView is added in the code.
I'd suggest you to use ImageView .Gravity = Gravity.Fill.
I have never used LoadBitmapSample, but there is something that looks a bit 'strange' to me:
You load a BitmapSample
imgtop.Bitmap = LoadBitmapSample(File.DirDefaultExternal,Main.pathimages&NewsImages.Get(i),110dip,130dip)
with a MaxWidth of 110dip and a MaxHeight of 130dip.
But the in this line
hsv.Panel.AddView(imgtop, itemSize * i, 0, 210dip, hsv.Panel.Height)
you add the image view with a width of 210dip which is bigger than the sample width and a height of hsv.Panel.Height which is probably also bigger than the 130dip.
I would try to set the dimensions in LoadBitmapSample the same as in hsv.Panel.AddView.
 
  • Like
Reactions: eps
Upvote 0
Top