Wish: Background patterns

alfcen

Well-Known Member
Licensed User
Longtime User
Is there any possibility of setting a background pattern for views like in CSS (background: url(image.png) repeat-x,y)?

Just an idea: View.Background.Tile(Files.DirAssets,"panelbg.png", [X,Y,Null]) 'default, both, X and Y.

This would help reduce application size.
 

alfcen

Well-Known Member
Licensed User
Longtime User
This can be implemented with the expense of a webview using CSS for tiling an image across the background.

B4X:
WebView1.Width = Activity.Width + 20dip
WebView1.ZoomEnabled = False
WebView1.LoadHtml("<html><body style='padding:0;margin:0; background: url(file:///android_asset/bg.gif) repeat;'></body></html>")

However, a solution without an extra view (or looping) may be more desirable.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I would seriously recommend just using 2 loops and drawing a bitmap yourself. Uses FAR less resources than a webview
 

thedesolatesoul

Expert
Licensed User
Longtime User
I think this should be the fastest / least code solution to do tiling on a view and leaving the OS to deal with the resource management.

B4X:
Sub TiledBackGround
   Dim bd As BitmapDrawable 
   bd.Initialize(LoadBitmap(File.DirAssets,"tileback.jpg"))
   
   Dim r As Reflector 
   r.Target = bd
   r.RunMethod3("setTileModeXY","REPEAT", "android.graphics.Shader$TileMode", _
                         "REPEAT", "android.graphics.Shader$TileMode")
   Activity.Background = bd
End Sub
 

maxtech1988

New Member
Licensed User
Longtime User
I think this should be the fastest / least code solution to do tiling on a view and leaving the OS to deal with the resource management.

B4X:
Sub TiledBackGround
   Dim bd As BitmapDrawable
   bd.Initialize(LoadBitmap(File.DirAssets,"tileback.jpg"))
  
   Dim r As Reflector
   r.Target = bd
   r.RunMethod3("setTileModeXY","REPEAT", "android.graphics.Shader$TileMode", _
                         "REPEAT", "android.graphics.Shader$TileMode")
   Activity.Background = bd
End Sub

Great Solution!

Works perfectly, really thx.
 

DonManfred

Expert
Licensed User
Longtime User
I think this should be the fastest / least code solution to do tiling on a view and leaving the OS to deal with the resource management.

Sounds like something good for the Snippet-Database ;-)
 
Top