Android Question [Solved] Round corner in AS ViewPager

asales

Expert
Licensed User
Longtime User
The AS ViewPager is a great lib from @Alexander Stolte .

I based in this example to create a slider with auto play and a label:

I'm trying to put a round corner in the panel of the slide, but I get this behaviour:
1725651057006.png

This is the code that I changed in the original example:
B4X:
Dim cor As Int   
For i = 0 To 5
    Dim tmp_xpnl As B4XView = xui.CreatePanel("")
    cor = xui.Color_ARGB(255,Rnd(1,255),Rnd(1,255),Rnd(1,255))
    tmp_xpnl.SetColorAndBorder(cor, 2dip, xui.Color_Gray, 30dip)
    tmp_xpnl.SetLayoutAnimated(0,0,0,ASViewPager1.Base.Width,ASViewPager1.Base.Height)
        
    Dim lb As Label
    lb.Initialize("lb")
    tmp_xpnl.AddView(lb, 25dip, 25dip, tmp_xpnl.Width - 50dip, tmp_xpnl.Height - 50dip)
    lb.Color = xui.Color_Cyan
    lb.TextColor = xui.Color_White
    lb.TextSize = 30
    lb.Text = "Test" & i
        
    ASViewPager1.AddPage(tmp_xpnl,"Test" & i)
Next
How I can set a border with the background transparent, like this:
1725651349758.png

Thanks in advance for any tip .
 
Solution
test
B4X:
Public Sub SetRectangleClip(pnl As B4XView, CornersRadius As Double)
    pnl.SetColorAndBorder(0, 0, 0, CornersRadius)
    #If B4J
    Dim Rectangle As JavaObject
    Dim cx = pnl.Width, cy = pnl.Height As Double
    Rectangle.InitializeNewInstance("javafx.scene.shape.Rectangle", Array(cx, cy))
    If CornersRadius > 0 Then
        Rectangle.RunMethod("setArcHeight", Array(CornersRadius))
        Rectangle.RunMethod("setArcWidth", Array(CornersRadius))
    End If
    pnl.As(JavaObject).RunMethod("setClip", Array(Rectangle))
    #Else If B4A
    pnl.As(JavaObject).RunMethod("setClipToOutline", Array(CornersRadius > 0))
    #End If
End Sub

TILogistic

Expert
Licensed User
Longtime User
test
B4X:
Public Sub SetRectangleClip(pnl As B4XView, CornersRadius As Double)
    pnl.SetColorAndBorder(0, 0, 0, CornersRadius)
    #If B4J
    Dim Rectangle As JavaObject
    Dim cx = pnl.Width, cy = pnl.Height As Double
    Rectangle.InitializeNewInstance("javafx.scene.shape.Rectangle", Array(cx, cy))
    If CornersRadius > 0 Then
        Rectangle.RunMethod("setArcHeight", Array(CornersRadius))
        Rectangle.RunMethod("setArcWidth", Array(CornersRadius))
    End If
    pnl.As(JavaObject).RunMethod("setClip", Array(Rectangle))
    #Else If B4A
    pnl.As(JavaObject).RunMethod("setClipToOutline", Array(CornersRadius > 0))
    #End If
End Sub
 
Upvote 1
Solution

Alexander Stolte

Expert
Licensed User
Longtime User
test
B4X:
Public Sub SetRectangleClip(pnl As B4XView, CornersRadius As Double)
pnl.SetColorAndBorder(0, 0, 0, CornersRadius)
 #If B4J
Dim Rectangle As JavaObject
Dim cx = pnl.Width, cy = pnl.Height As Double
Rectangle.InitializeNewInstance("javafx.scene.shape.Rectangle", Array(cx, cy))
If CornersRadius > 0 Then
Rectangle.RunMethod("setArcHeight", Array(CornersRadius))
Rectangle.RunMethod("setArcWidth", Array(CornersRadius))
End If
pnl.As(JavaObject).RunMethod("setClip", Array(Rectangle))
#Else If B4A
pnl.As(JavaObject).RunMethod("setClipToOutline", Array(CornersRadius > 0))
#End If
End Sub
what he says
 
Upvote 0

asales

Expert
Licensed User
Longtime User
test
B4X:
Public Sub SetRectangleClip(pnl As B4XView, CornersRadius As Double)
    pnl.SetColorAndBorder(0, 0, 0, CornersRadius)
    #If B4J
    Dim Rectangle As JavaObject
    Dim cx = pnl.Width, cy = pnl.Height As Double
    Rectangle.InitializeNewInstance("javafx.scene.shape.Rectangle", Array(cx, cy))
    If CornersRadius > 0 Then
        Rectangle.RunMethod("setArcHeight", Array(CornersRadius))
        Rectangle.RunMethod("setArcWidth", Array(CornersRadius))
    End If
    pnl.As(JavaObject).RunMethod("setClip", Array(Rectangle))
    #Else If B4A
    pnl.As(JavaObject).RunMethod("setClipToOutline", Array(CornersRadius > 0))
    #End If
End Sub
Thanks!
Solved with this line before the for:
B4X:
SetRectangleClip(ASViewPager1.Base, 30dip)
 
Upvote 0
Top