Dim logoBox As ImageView
logoBox.Initialize("")
logoBox.Bitmap = LoadBitmap(File.DirAssets, "logo.png")
#if B4a
logoBox.Gravity = Gravity.CENTER
#else if B4i
' come lo traduco in b4i (logoBox.Gravity = Gravity.CENTER)
#End If
Root.AddView(logoBox, 0, 0, 100%x, 200dip)
In b4i non funziona.
Esiste una versione b4x che va bene per le entrambe versioni?
Grazie mille
Ciao ho importato la libreria ora che modifica devo fare al codice che ho scritto? Mi puoi far vedere come va usata ? Nella versione b4a il logo va al centro ..Grazie mille
Public logoBox As B4XView
Public ImageView1 As B4XView
logoBox = LoadBitmap(File.DirAssets, "logo.png")
logoBox.SetTextAlignment("CENTER", "CENTER")
Root.AddView(logoBox, 0, 0, 100%x, 200dip)
Dim b As B4XBitmap=xui.LoadBitmapResize(File.DirAssets,"logo.png", 50dip, 50dip, True) 'resizes the image
ImageView1.setbitmap(b)
Root.AddView(ImageView1, 0, 0, 100%x, 200dip)
Il mio scopo è mettere il logo al centro senza essere deformato
in b4a lo provato sia col telefono che col tablet tutto ok
in b4i senza la proprietà il logo si deforma e si allunga
Grazie mille per aiuto
Su Custom view non ho trovato la proprietà per caricare il logo allora ho usato imaview posto il codice
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click To sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click To export As zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private logo As ImageView
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
AlignImageCenter(logo)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name Is B4XPage.
Private Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Sub AlignImageCenter(img As ImageView)
Dim ImageView As ImageView
ImageView = img.Parent
If ImageView.IsInitialized Then
Dim centerX As Int = (ImageView.Width - img.Width) / 2
Dim centerY As Int = (ImageView.Height - img.Height) / 2
img.Left = centerX
img.Top = centerY
End If
End Sub
Mi da questo errore
JSON:
Application_Start
*** mainpage: B4XPage_Created
Error occurred on line: 34 (B4XMainPage)
Expected: UIImageView, object type: B4IPanelView
Stack Trace: (
CoreFoundation __exceptionPreprocess + 242
libobjc.A.dylib objc_exception_throw + 48
CoreFoundation -[NSException initWithCoder:] + 0
B4i Example -[B4IObjectWrapper setObject:] + 235
B4i Example +[B4IObjectWrapper createWrapper:object:] + 101
B4i Example -[b4i_b4xmainpage _alignimagecenter::] + 644
B4i Example -[b4i_b4xmainpage _b4xpage_created::] + 616
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 305
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
B4i Example -[B4ICommon CallSubDebug4::::] + 975
B4i Example -[B4ICommon CallSubDebug2::::] + 305
B4i Example -[b4i_b4xpagesmanager _createpageifneeded::] + 975
B4i Example -[b4i_b4xpagesmanager _showpage::] + 709
B4i Example -[b4i_b4xpagesmanager _addpage:::] + 1271
B4i Example -[b4i_b4xpagesmanager _addpageandcreate:::] + 538
B4i Example -[b4i_b4xpagesmanager _initialize:::] + 1635
B4i Example -[b4i_main _application_start:] + 575
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 305
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
B4i Example -[B4IShell runMethod:] + 380
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2076
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1358
B4i Example __33-[B4I raiseUIEvent:event:params:]_block_invoke + 51
libdispatch.dylib _dispatch_call_block_and_release + 12
libdispatch.dylib _dispatch_client_callout + 8
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1075
CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
CoreFoundation __CFRunLoopRun + 2772
CoreFoundation CFRunLoopRunSpecific + 567
GraphicsServices GSEventRunModal + 139
UIKitCore -[UIApplication _run] + 928
UIKitCore UIApplicationMain + 101
B4i Example main + 104
dyld start_sim + 10
??? 0x0 + 1
)
Application_Active
Dim logoBox As ImageView
logoBox.Initialize("")
logoBox.Bitmap = LoadBitmap(File.DirAssets, "logo.png")
#if B4a
logoBox.Gravity = Gravity.CENTER
#else if B4i
' come lo traduco in b4i (logoBox.Gravity = Gravity.CENTER)
#End If
Root.AddView(logoBox, 0, 0, 100%x, 200dip)
In b4i non funziona.
Esiste una versione b4x che va bene per le entrambe versioni?
Grazie mille
Ho il vago sospetto che non ci capiamo.
Secondo me dovresti usare NON ImageView ma B4XImageView, che fa parte della libreria XUI Views, come già detto (e ovviamente anche dichiararla come B4XImageView)
Su Custom view non ho trovato la proprietà per caricare il logo allora ho usato imaview posto il codice
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click To sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click To export As zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private logo As ImageView
End Sub
Public Sub Initialize
B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
AlignImageCenter(logo)
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name Is B4XPage.
Private Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Sub AlignImageCenter(img As ImageView)
Dim ImageView As ImageView
ImageView = img.Parent
If ImageView.IsInitialized Then
Dim centerX As Int = (ImageView.Width - img.Width) / 2
Dim centerY As Int = (ImageView.Height - img.Height) / 2
img.Left = centerX
img.Top = centerY
End If
End Sub
Mi da questo errore
JSON:
Application_Start
*** mainpage: B4XPage_Created
Error occurred on line: 34 (B4XMainPage)
Expected: UIImageView, object type: B4IPanelView
Stack Trace: (
CoreFoundation __exceptionPreprocess + 242
libobjc.A.dylib objc_exception_throw + 48
CoreFoundation -[NSException initWithCoder:] + 0
B4i Example -[B4IObjectWrapper setObject:] + 235
B4i Example +[B4IObjectWrapper createWrapper:object:] + 101
B4i Example -[b4i_b4xmainpage _alignimagecenter::] + 644
B4i Example -[b4i_b4xmainpage _b4xpage_created::] + 616
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 305
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
B4i Example -[B4ICommon CallSubDebug4::::] + 975
B4i Example -[B4ICommon CallSubDebug2::::] + 305
B4i Example -[b4i_b4xpagesmanager _createpageifneeded::] + 975
B4i Example -[b4i_b4xpagesmanager _showpage::] + 709
B4i Example -[b4i_b4xpagesmanager _addpage:::] + 1271
B4i Example -[b4i_b4xpagesmanager _addpageandcreate:::] + 538
B4i Example -[b4i_b4xpagesmanager _initialize:::] + 1635
B4i Example -[b4i_main _application_start:] + 575
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 305
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
B4i Example -[B4IShell runMethod:] + 380
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2076
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1358
B4i Example __33-[B4I raiseUIEvent:event:params:]_block_invoke + 51
libdispatch.dylib _dispatch_call_block_and_release + 12
libdispatch.dylib _dispatch_client_callout + 8
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1075
CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
CoreFoundation __CFRunLoopRun + 2772
CoreFoundation CFRunLoopRunSpecific + 567
GraphicsServices GSEventRunModal + 139
UIKitCore -[UIApplication _run] + 928
UIKitCore UIApplicationMain + 101
B4i Example main + 104
dyld start_sim + 10
??? 0x0 + 1
)
Application_Active
Sub AlignImageCenter(img As ImageView)
Dim ImageView As ImageView
ImageView = img.Parent
If ImageView.IsInitialized Then
Dim centerX As Int = (ImageView.Width - img.Width) / 2
Dim centerY As Int = (ImageView.Height - img.Height) / 2
img.Left = centerX
img.Top = centerY
End If
End Sub
Scrivi nel designer queste 2 rige, e non si deforma niente.