I have a panel set with a background image through the designer with gravity Fill option. In the same panel few other controls also located. But In the run time how can I change the background image without modifying the any other properties of panel.
I tried with SetBackGroundImage() and Invalidate() after that. But it did not work.
You are correct. It is a bit more complicated.
You have two options.
1. Put an ImageView on the Panel and assign the images to the ImageView instead of the Panel.
2.
B4X:
Dim bd As BitmapDrawable
bd.Initialize(LoadBitmap(...))
bd.Gravity = Gravity.FILL
panel1.Background = bd
I followed the 2nd method, still the background image is not changing.
I tried like by default I set the panel background as Color drawable, and in the code 2nd method as you mentioned above. But still its not displaying.
Any update on the above one. I wanted this info for immediate implementation. Even I tried with ImageView, its not updating its image in runtime. The thing I found is If you remove the image view and add it again it works. If there is no other solution means I have to go with this solution.
One more thing I wanted is When image view with image is displyed it should be in background, because other button controls are hidden below the image.
This code changes the panel background when you click on the activity:
B4X:
Sub Globals
Dim p As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
p.Initialize("")
Activity.AddView(p, 0, 0, 100dip, 100dip)
p.Color = Colors.Yellow
End Sub
Sub Activity_Click
Dim bd As BitmapDrawable
bd.Initialize(LoadBitmap(File.DirAssets, "button.png"))
bd.Gravity = Gravity.FILL
p.Background = bd
End Sub
Erel, thanks for the inputs.
But in my scenaro, I am adding a panel to activity with around 10-15 buttons in different locations in the panel. So I am not adding panel in the code. only from the designer. Thats why its not changing the image at runtime :BangHead: Any inputs for this issue?
Try to add a panel in the designer with bitmapdrawable and with a bitmap, and try to change the bitmap in the any part of the code at runtime.
I tried with the small application its working! But from my application, (few more things have been done), Its not displaying the image. I am following the same method as in the sample you have given
I am wondering what may be the problem?:BangHead:
It would be much more efficient if you posted your project as a zip file so we could see what you are doing wrong.
You are asking for help but you don't show what you have done, whithout seeing your code how could you expect us guess what you have done.
Finally its working, But the thing I found is, it works only if I add,
Activity.AddView(panel, 0, 30, 320, 280) in the activity_create, even though panel is added through designer. If I remove the above line, then background image will not br updated to new image.
What may be the reason for this one?