Android Question Adding a view in code

mjtaryan

Active Member
Licensed User
Longtime User
I am adding a panel to an app in code. The panel is not to have rounded corners. The default in the Designer is for a corner radius of 5. How can I change this programatically to 0? Thanks.
 

mangojack

Expert
Licensed User
Longtime User
Hi .. Are you changing the panels background property ? .. Adding a panel in code results in no rounded corners here unless purposely set.

This results in no rounded corners ...
B4X:
 Dim Panel1 As Panel
Panel1.Initialize("")
Panel1.Color = Colors.Blue
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)


This results in corner radius of 10 ... can be set to 0 if this is what your after ..
B4X:
 Dim cd As ColorDrawable
cd.Initialize(Colors.Blue,10) 'corner radius = 10 ... set to 0 for no rounded corner

Dim Panel1 As Panel
Panel1.Initialize("")  
Panel1.Background = cd
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)

Cheers mj
 
Last edited:
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Hi .. Are you changing the panels background property ? .. Adding a panel in code results in no rounded corners here unless purposely set....

Thanks. I hadn't intended to change the background property, but I can. I was actually hoping for a more direct and straight forward method, but given that the corner radius property is only indirectly available in coding, your schema will work nicely. (It would be great if all the properties were available in both the Designer and through code - hint to Erel). Thanks again.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
mjtaryan said:
I am adding a panel to an app in code. The panel is not to have rounded corners.

I'm confused ... if you add a panel by way of code by default it does NOT have rounded corners
B4X:
Dim Panel1 As Panel
Panel1.Initialize("")
Panel1.Color = Colors.Blue
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)

Cheers mj
 
Last edited:
Upvote 0

dualznz

Member
Licensed User
Longtime User
B4X:
Dim cd AsColorDrawable
cd.Initialize(Colors.Blue,10) 'corner radius = 10 ... set to 0 for no rounded cornerDim Panel1 AsPanel
Panel1.Initialize("")
Panel1.Background = cd
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)

this is how you add a radius to the panel1.
the code that you have provided is for a non cornered radius

B4X:
Dim Panel1 As Panel
Panel1.Initialize("")
Panel1.Color = Colors.Blue
Activity.AddView(Panel1,20dip,20dip,300dip,300dip)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
dualznz said:
the code that you have provided is for a non cornered radius

That is correct because ...
mjtaryan said:
I am adding a panel to an app in code. The panel is not to have rounded corners.

"the panel is NOT to have rounded corners" ...

maybe my first post #2 could have been clearer or am i missing something here .. ?

Cheers mj
 
Upvote 0

dualznz

Member
Licensed User
Longtime User
no in your code u were only creating a rectangle box panel without any radius
by default this is the case when coding the views

when you add the
B4X:
Dim cd AsColorDrawable
cd.Initialize(Colors.Blue,10) 'corner radius = 10 ... set to 0 for no rounded cornerDim Panel1 AsPanel

it will then initialize a radius that will be attached to the panel view.

ok so looking at your first post if you dont want a radius you can either just not initiate a radius to draw or just ad 0 then it wont add a radius to the panel
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
dualznz said:
no in your code u were only creating a rectangle box panel without any radius
by default this is the case when coding the views

Correct again .. because that is what mjtaryan wanted .. A panel WithOut any radius
as I stated in #4 .. "if you add a panel by way of code by default it does NOT have rounded corners"

thats it from me .. lol
Cheers mj
 
Upvote 0

mjtaryan

Active Member
Licensed User
Longtime User
Correct again .. because that is what mjtaryan wanted .. A panel WithOut any radius
as I stated in #4 .. "if you add a panel by way of code by default it does NOT have rounded corners"

thats it from me .. lol
Cheers mj

I asked the original question because the Designer default is rounded corners with a radius of 5. Until now I've always added the panels I needed in the Designer and reset the radii to 0 there. I've not added a panel in code before and thought all the defaults from the Designer would carry over to code. That is why asked the question.

However, my current project makes an array of panels more efficient which is more easily accomplished in code. Using the code snippet in post #2 (not the rounded corners) I did a little experimenting and discovered that only creating and initializing the panel and then adding it to its intended parent is all that is absolutely necessary to get corners with a radius of 0. Everything else is merely refinement. Therefore, for my purposes, I don't need to reset the panel's color property, which is shown in the snippet. Thanks for the help mj.

I wish (hint to Erel) a) that all the properties could be set directly EITHER in the Designer or in code and b) the property defaults were consistent and the same whether set in the Designer or in code. But at least for now that is not the way it is.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…