Android Question Corner Radius disappears

strupp01

Active Member
Licensed User
Longtime User
I have a program that causes the curves of the corners of a panel to disappear when I change a radio button.
I have enclosed a test program. (Test_Corner.zip)
If the program is started and the radio button "Test1" is pressed, a red panel with rounded corners and a vertical line appears.
If the "Test2" radio button is then pressed, the same panel appears in green without rounded corners, but without a vertical line. The curves at the corners are gone.
If you then press the “Test1” radio button again, the red panel with the vertical line appears again. But the rounded corners are now missing here too.
Question1: Can I prevent the rounded corners from disappearing when using Canvas?
Question 2: If I can't prevent it, how can I restore the rounding of the corners using program code.

Sorry for the bad English. Must work with Google Translate.

Greetings strupp01
 

Attachments

  • Test_Corner.zip
    10.5 KB · Views: 42

Mahares

Expert
Licensed User
Longtime User
Can I prevent the rounded corners from disappearing when using Canvas?
Give both radio buttons the same event name: rb and use this code instead of the codes you have for each of the radio buttons. Also give radiobutton1 a tag of 1, the other one a tag of 2 in the designer:
B4X:
Sub rb_CheckedChange(Checked As Boolean)
    Dim r As RadioButton = Sender
    Panel_mit_Radius.Height = 36%y
    Panel_mit_Radius.RemoveAllViews
    If 1 = r.Tag  Then   'give radiobutton1 a tag of 1, the other one a tag o2 in the designer
        Dim cd As ColorDrawable
        cd.Initialize2(Colors.Red, 20dip, 6dip, Colors.Black)
        Panel_mit_Radius.Background = cd
        HorizontalScrollView1.Initialize(100%x, "HorizontalScrollView1")
        Panel_mit_Radius.AddView(HorizontalScrollView1, 2%x, 7%y, 20%x, Panel_mit_Radius.Height - 10%y)'63%y)
        HorizontalScrollView1.Panel.RemoveAllViews        
    Else
        Dim cd As ColorDrawable
        cd.Initialize2(Colors.green, 20dip, 6dip, Colors.Black)
        Panel_mit_Radius.Background = cd
        HorizontalScrollView2.Initialize(100%x, "HorizontalScrollView2")
        Panel_mit_Radius.AddView(HorizontalScrollView2, 2%x, 7%y, 20%x, Panel_mit_Radius.Height - 10%y)'63%y)
        HorizontalScrollView2.Panel.RemoveAllViews
    End If
    Canvas1.Initialize(Panel_mit_Radius)
    Canvas1.DrawLine(30dip, 10dip, 30dip, 50dip, Colors.Black, 3dip)    'Y-Koordinate
'    Activity.Invalidate
End Sub
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
I have now carried out the test in my example. Yes, that's how it works.
Thanks again.
Greetings strupp01
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Ok, please report back. Note that I tested my code before posting it. Here are the screenshots:

1700091018383.png

1700091120666.png
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of using ColorDrawable you could use the code below with XUI.

Replace in your original code this line:
B4X:
Panel_mit_Radius.Color = Colors.Red
by this one:
B4X:
Panel_mit_Radius.As(B4XView).SetColorAndBorder(xui.Color_Red, 0, xui.Color_Black, 20dip)

And the same for the green color.

You could, of course, also use the proposal of Mahares with the single event routine and there replace these codes by the single xui line of code.
B4X:
    Dim cd As ColorDrawable
    cd.Initialize2(Colors.Red, 20dip, 6dip, Colors.Black)
    Panel_mit_Radius.Background = cd
 
Last edited:
Upvote 1

strupp01

Active Member
Licensed User
Longtime User
Thanks also to you Klaus for your suggestions. I was irritated that the panel curves were suddenly no longer present in my large program. I searched for a long time until I found out that this happened through a canvas command. I didn't expect that a specification that was set in the designer would be reset by a completely different command.
You're always learning something new.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
searched for a long time until I found out that this happened through a canvas command. I didn't expect that a specification that was set in the designer would be reset by a completely different command.
It has nothing to do with the presence of the canvas. Your code in your project did not work because when you use a colordrawable once in the designer like you did, you cannot reuse it with another view. You have to reinitialize the colordrawable again. Therefore, your project would have worked fine if you left everything the way you had it and only replaced your sub: Sub RadioButton2_CheckedChange(Checked As Boolean) with this code:
B4X:
Sub RadioButton2_CheckedChange(Checked As Boolean)    
    Panel_mit_Radius.Height = 36%y
    Panel_mit_Radius.RemoveAllViews
    Dim cd As ColorDrawable
    cd.Initialize2(Colors.green, 20dip, 0dip, Colors.transparent)
    Panel_mit_Radius.Background = cd    
    HorizontalScrollView2.Initialize(100%x, "HorizontalScrollView2")
    Panel_mit_Radius.AddView(HorizontalScrollView2, 2%x, 7%y, 20%x, Panel_mit_Radius.Height - 10%y)'63%y)
    HorizontalScrollView2.Panel.RemoveAllViews
End Sub
Check it out for yourself first. You will see.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It has nothing to do with the presence of the canvas.
Yes it has.
If you comment, in the original code, the lines related to the Canvas the corners remain round.
I tested it.

And you are right that the Android ColorDrawable object does not have the CornerRadius properts.
The GradientDrawabel object has it.
But in B4A the ColorDrawable is in reality a kind of GradientDrawable with only one color.
I do not know what happes to the Panel background when a Canvas is connected to the Panel.

I have checked the type of a ColorDrawable and i get this:
anywheresoftware.b4a.objects.drawable.ColorDrawable$GradientDrawableWithCorners
For a GradientDrawable i get this.
android.graphics.drawable.GradientDrawable
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
f you comment, in the original code, the lines related to the Canvas the corners remain round.
But if you do not comment the canvas code and reinitialize the colordrawable, the second button code works and you get your rounded corners. I tested it
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
But if you do not comment the canvas code and reinitialize the colordrawable, the second button code works and you get your rounded corners. I tested it
Yes sure, I know !
My comment was for the original code.
When using Panel_mit_Radius.Color = Colors.Red, and a canvas the corner radii disappear, but without the Canvas they remain.
 
Upvote 0
Top