Android Question How to change picture after load layout

csdev

New Member
Licensed User
Hi all!
I have a layout with imageview setted with picture. In Activity, after some condition, i need to change this picture in imageview but when i do i lose the autoscale settings. There is a way to recall script or i need to use different layout?
If i reload the layout, it is also reload the old image.
 

Salar82

Member
Hi
If you want change picture of Imageview, you should use this code:

B4X:
ImageView1.Bitmap = LoadBitmap(File.DirAssets , "NewPic.png")
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm not sure what you mean by "autoscale" but, have you tried:
B4X:
ImgaeView1.SetBackgroundImage(LoadBitmap(File.DirAssets, "newimage.jpg"))
ImgaeView1.Gravity = Gravity.FILL
If that is not what you are after, you should look at the LoadBitmapResize method instead of the LoadBitmap method.
 
Upvote 0

csdev

New Member
Licensed User
Thank you for replys. I'm already use this code for change the picture but all setting that i write in "variant script" of layout are lost after change image.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but all setting that i write in "variant script" of layout are lost after change image.
this script is only executed when loading a layout.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You need to explain what exactly you want or need or expect.
You are the developer, so I hope that you know what you are doing.
If you need to reuse settings, you need to memorize them somewhere to be able to reuse them.
You decide when and how you change settings, so if you need the original ones you must memorize these.
Sorry, but, I don't really understand your problem!?
 
Upvote 0

csdev

New Member
Licensed User
You need to explain what exactly you want or need or expect.
You are the developer, so I hope that you know what you are doing.
If you need to reuse settings, you need to memorize them somewhere to be able to reuse them.
You decide when and how you change settings, so if you need the original ones you must memorize these.
Sorry, but, I don't really understand your problem!?

Sorry... maybe i'm not explain in the right way...

It is simple... I made a layout with fixed object, fixed object size and position. I load a layout when i load the activity/page. This is ok... but if i want to change some picture linked to one or more object (imageview in this case) i lose all settings of layout. The object size are changed.

Layout logic is good because you can configure a different screen resolution but i don't think that is good to repeat all this logic in the main app code. Redundant code and time loss.

All that i request is: there is some way to change, in programmatically way, the picture associated to imageview object withouth lose size setted from layout?

N.B. Already tried with LoadBitmap, LoadBitmapResize and Gravity's property but not is the result that i want.

I wish you a good day!
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Sorry... maybe i'm not explain in the right way...

It is simple... I made a layout with fixed object, fixed object size and position. I load a layout when i load the activity/page. This is ok... but if i want to change some picture linked to one or more object (imageview in this case) i lose all settings of layout. The object size are changed.

Layout logic is good because you can configure a different screen resolution but i don't think that is good to repeat all this logic in the main app code. Redundant code and time loss.

All that i request is: there is some way to change, in programmatically way, the picture associated to imageview object withouth lose size setted from layout?

N.B. Already tried with LoadBitmap, LoadBitmapResize and Gravity's property but not is the result that i want.

I wish you a good day!

Hi CSDEV,
As with everything, it starts with determining which goal you want to achieve, because your mentioned applied means doesn't make that clear. Of-course if you start with a let say 200 x 100 and replace it by an image from let say 150 x 300 then it doesn't fit. So you have to make a choose what to do with things like the ratio between length and width or fill in the original length completely with distortion as a result.

Erel has written about and shows the results about different ways to display images at [B4X][XUI] Fill and Fit images without distortion. After reading the post and looking to the pictures you can made you choice in what you want or not want to archive.
 
Upvote 0
Top