Android Question ScrollView - Best way to add a border?

ArminKH

Well-Known Member
You can add a border with the designer. It will add it to the inner panel.

You can use ColorDrawable to add it to the ScrollView itself.
also this can be done by using this code
B4X:
Sub AddBorder2View (V As View, FillColor As Int, StrokeColor As Int, rx As Float, ry As Float, SWidth As Float, Padding As Int)
        Dim BM As Bitmap
        Dim BMD As BitmapDrawable
        Dim Cnv As Canvas
        'We need to draw on the bitmap with a canvas
        BM.InitializeMutable(V.Width,V.Height)
        Cnv.Initialize2(BM)
        'Sizing Variables need to be cast to floats to enable the constructor to be found.
        Dim l,T,r,b As Float
        l = 0
        T = 0
        r = V.Width
        b = V.Height
        'Needs a RectF object not just a Rect
        Dim rect1 As JavaObject
        rect1.InitializeNewInstance("android.graphics.RectF",Array As Object(l,T,r,b))
        'Create a Paint.Style object
        Dim PS As JavaObject
        PS.InitializeStatic("android.graphics.Paint.Style")
        'Create and setup a Paint object
        Dim Paint,Paint1 As JavaObject
        Paint.InitializeNewInstance("android.graphics.Paint",Null)
        Paint.RunMethod("setStrokeWidth",Array As Object(SWidth))
        Paint.RunMethod("setColor",Array As Object(StrokeColor))
        Paint.RunMethod("setStyle",Array As Object(PS.GetField("STROKE")))
        Paint.RunMethod("setAntiAlias",Array As Object(True))
    
        Paint1.InitializeNewInstance("android.graphics.Paint",Null)
        Paint1.RunMethod("setColor",Array As Object(FillColor))
        Paint1.RunMethod("setAntiAlias",Array As Object(True))
        Paint1.RunMethod("setStyle",Array As Object(PS.GetField("FILL")))
    
        'Get the canvas object from the wrapper
        Dim CnvJO As JavaObject = Cnv
        CnvJO = CnvJO.GetField("canvas")
        'Draw the filled round rect on the bitmap using the canvas
        CnvJO.RunMethod("drawRoundRect",Array As Object(rect1,rx,ry,Paint1))
        'Draw the border round rect on the bitmap using the canvas
        CnvJO.RunMethod("drawRoundRect",Array As Object(rect1,rx,ry,Paint))
        'Cast the Bitmap to a BitmapDrawable
        BMD.Initialize(BM)
        If Padding <> -1 And GetType(V) = "android.widget.TextView" Then
            Dim VJO As JavaObject = V
            VJO.RunMethod("setPadding",Array As Object(Padding,Padding,Padding,Padding))
        End If
        'Add it to the view
        V.Background = BMD
End Sub
for example:
B4X:
AddBorder2View(ScrollView1,Colors.Transparent,Colors.RGB(150,150,150),0,0,1Dip,1dip)
i don't tried this for long time maybe this is correct
B4X:
AddBorder2View(ScrollView1.Panel,Colors.Transparent,Colors.RGB(150,150,150),0,0,1Dip,1dip)
 
Last edited:
Upvote 0
Top