Panels, bitmaps & Labels Help request

JTmartins

Active Member
Licensed User
Longtime User
Hello guys,

I do needed some help, which I believe it's so easy for some of you, but I still haven't found a good tutorial.

All i need is an example of how to, in programmatic way (without touching designer) do the following :

Create a panel of x by y dimension with a background (gradient if possible)
add a bitmap of size x,y at position (x,y) off that panel
add a label of size x,y at position (x,y) of that panel with font size F

I do want to learn a little bit more of this stuff to play around.

Thanks
José
 

Mahares

Expert
Licensed User
Longtime User
Jose: Here is a simple example in code that has the features you were looking for to play with. This will get you started. Then you can build on it and improve:
B4X:
Sub Globals
   Dim pnlJose As Panel
   Dim lblJose As Label
   Dim bmpJose As Bitmap
   Dim imgJose As ImageView
   Dim Gradient1 As GradientDrawable
End Sub

Sub Activity_Create(FirstTime As Boolean)
      'Initialize
      pnlJose.Initialize("")
      imgJose.Initialize("")
      lblJose.Initialize("")
      
      'Gradient
      Dim Clrs(3) As Int
      Clrs(0) = Colors.RGB(255,0,0)
      Clrs(1) = Colors.RGB(128,255,128)
      Clrs(2) = Colors.RGB(255,176,255)
      Gradient1.Initialize("LEFT_RIGHT", Clrs)
      pnlJose.Background=Gradient1
      
      'Label
      lblJose.Text="JTMartins"
      lblJose.TextColor=Colors.Black
      lblJose.Typeface=Typeface.DEFAULT_BOLD
      lblJose.TextSize=22

      'Add views to panel
      pnlJose.AddView(imgJose,0,25%y,50%x,150dip)
      pnlJose.AddView(lblJose,50%x,25%y,150dip,50dip)

      'Add panel to activity
      Activity.AddView(pnlJose,0,0,100%x,50%y)
      imgJose.Bitmap=LoadBitmap(File.DirAssets,"yourpngfile.png")  
End Sub
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Thank you

I think it's easier for me to get the grips in all this screen stuff manually.

I really don't care the extra work. I'm sure I'll get much more flexibility.

Many thanks for your time.

José
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
So Why do we DIM ?????

I was looking at the code, and a question came up

Why do we dim

Dim bmpJose As Bitmap


If we never use it ?

Thanks
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
In The code I sent you you did not need to dim Bitmap because there is no variable used for it. But if you are going to use any variable in the code you need to dim it. Any view like edittext, panel, label must be dimmed if you are going to use it in code regardless whether it is created in code or designer. For instance, you can add a label in designer, but if you are not going to use it in code, then you do not need to dim or intialize.
The moment you have this: Suppose you have this in code: MyLabel.visible=False . If you do not dim the label and initialize it in code you will get an error.
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
Understood

I played a little last night, and I think I'm starting to understand this way of doing things without designer.

It's a little more painful...but at least I know what I'm doing, and how to control things in a much better way.

Still a lot to learn, but it's fun to be able to do, things I was not being able to do with designer only.

Many thanks for your help

Jose
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…