Android Question Iconbutton problem

grafsoft

Well-Known Member
Licensed User
Longtime User
I have an Inconbutton with a circle layout. See the code below. The microphone picture should be smaller than the button, so that you can see the microphone on a blue disc.

On a device with lower resolution it works perfectly. On one with higher resolution you see only part of it. I hope the screenshots make it clear.

What can I do?

Thanks a lot.

B4X:
   Dim b As IconButton
   Dim rad As Int = 40dip
   b.initialize ("touchbtn")
   c=Main.a100color
   Dim cd As ColorDrawable
   cd.Initialize (c,rad)
   b.Background=cd
   Dim bb As Bitmap     
   bb.Initialize(File.DirAssets,"ic_microphone_black_48dp.png")
   bb=CreateScaledBitmap (40dip*2/3,40dip*2/3,True)
   Dim bm As BitmapDrawable
   bm.Initialize (bb)
   b.IconPadding=1dip
   b.setIcon(False,bm)
   
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
  Dim r As Reflector
  Dim b As Bitmap
  b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
  Array As Object(Original, Width, Height, Filter), _
  Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
  Return b
End Sub
 

Attachments

  • 20160214_174909.jpg
    20160214_174909.jpg
    306.4 KB · Views: 410
  • Screenshot_2016-02-19-19-28-17.jpg
    Screenshot_2016-02-19-19-28-17.jpg
    171.7 KB · Views: 376

DonManfred

Expert
Licensed User
Longtime User
I dont know why this happens.
Just wondering why you want to change the size.
Dim bb As Bitmap
bb.Initialize(
File.DirAssets,"ic_microphone_black_48dp.png")
should do the work to set the image
bb=CreateScaledBitmap (40dip*2/3,40dip*2/3,True)
does not look that is not creating an error as there are a parameter missing
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
In my code only the BitmapDrawable has a gravity property. Setting this to fill does not help - see test project. What am I doing wrong?
 

Attachments

  • testit.zip
    7.9 KB · Views: 373
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see the problem.

Use this method instead:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim bd As BitmapDrawable
   bd.Initialize(CreateScaledBitmap2(LoadBitmap(File.DirAssets, "ic_microphone_black_48dp.png"), 40dip, 40dip, True))
   Dim ib As IconButton
   ib.Initialize("")
   ib.setIcon(False, bd)
   Activity.AddView (ib,50%x,50%y, 80dip, 50dip)
     
End Sub

Sub CreateScaledBitmap2(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
   Dim graphics As JavaObject
   graphics = graphics.InitializeStatic("android.graphics.Bitmap").RunMethod("createScaledBitmap", Array(Original, Width, Height, Filter))
   graphics.RunMethod("setDensity", Array(160dip))
   Return graphics
End Sub
 
Upvote 0
Top