Italian Problemi proprietà gravity applicata in un logo

ken87

Active Member
Licensed User
Longtime User
In B4a questo funziona
B4X:
    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
 

ken87

Active Member
Licensed User
Longtime User
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
 

LucaMs

Expert
Licensed User
Longtime User
Le possibilità che hai sono queste:

1686065966719.png
 

ken87

Active Member
Licensed User
Longtime User
Ho fatto queste prove ma vanno in errore

B4X:
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)

XML:
Application_Start
Error occurred on line: 61 (B4XMainPage)
Object was not initialized (UIView)
Stack Trace: (
  CoreFoundation       __exceptionPreprocess + 242
  libobjc.A.dylib      objc_exception_throw + 48
  CoreFoundation       -[NSException initWithCoder:] + 0
  Petrarca Utility     -[B4IObjectWrapper object] + 111
  Petrarca Utility     -[B4XViewWrapper SetBitmap:] + 49
  CoreFoundation       __invoking___ + 140
  CoreFoundation       -[NSInvocation invoke] + 305
  Petrarca Utility     +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
  Petrarca Utility     -[B4IShell runVoidMethod] + 184
  Petrarca Utility     -[B4IShell raiseEventImpl:method:args::] + 1699
 Petrarca Utility     -[B4IShellBI raiseEvent:event:params:] + 1358
 Petrarca Utility     +[B4IDebug delegate:::] + 66
 Petrarca Utility     -[b4i_b4xmainpage _b4xpage_created::] + 318
 CoreFoundation       __invoking___ + 140
 CoreFoundation       -[NSInvocation invoke] + 305
 Petrarca Utility     +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
 Petrarca Utility     -[B4ICommon CallSubDebug4::::] + 975
 Petrarca Utility     -[B4ICommon CallSubDebug2::::] + 305
 Petrarca Utility     -[b4i_b4xpagesmanager _createpageifneeded::] + 975
 Petrarca Utility     -[b4i_b4xpagesmanager _showpage::] + 709
 Petrarca Utility     -[b4i_b4xpagesmanager _addpage:::] + 1271
 Petrarca Utility     -[b4i_b4xpagesmanager _addpageandcreate:::] + 538
 Petrarca Utility     -[b4i_b4xpagesmanager _initialize:::] + 1635
 Petrarca Utility     -[b4i_main _application_start:] + 575
 CoreFoundation       __invoking___ + 140
 CoreFoundation       -[NSInvocation invoke] + 305
 Petrarca Utility     +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
 Petrarca Utility     -[B4IShell runMethod:] + 380
 Petrarca Utility     -[B4IShell raiseEventImpl:method:args::] + 2076
 Petrarca Utility     -[B4IShellBI raiseEvent:event:params:] + 1358
 Petrarca Utility     __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
 Petrarca Utility     main + 104
 dyld                 start_sim + 10
 ???                  0x0 + 1
 ???                  0x0 + 1
)
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
Application_Active

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
 

ken87

Active Member
Licensed User
Longtime User
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

Posto anche il progetto di prova in b4x

L'ho provato sia in b4a che in b4i va in errore
 

Attachments

  • B4A.rar
    23 KB · Views: 113
  • B4i.rar
    182.1 KB · Views: 110

ken87

Active Member
Licensed User
Longtime User
Ho dovuto togliere cartelle in quanto i file mi diceva che era troppo grande
.Grazie per ora
 

Filippo

Expert
Licensed User
Longtime User
In B4a questo funziona
B4X:
    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
Non capisco perchè non usi le funzioni del Designer, ha tutto quello che ti serve.
1686134686072.png
 

LucaMs

Expert
Licensed User
Longtime User
Su Custom view non ho trovato la proprietà per caricare il logo allora ho usato imaview posto il codice
Dim ImageView As ImageView
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)

Il tuo rar b4a non va, b4i non ce l'ho, ergo...!
 

Filippo

Expert
Licensed User
Longtime User
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

Posto anche il progetto di prova in b4x

L'ho provato sia in b4a che in b4i va in errore
Intanto questo Sub non ti serve.
B4X:
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.
B4X:
logo.HorizontalCenter = 50%x
logo.Height = 141 * logo.Width / 240

Nota, 141 è l'altezza e 240 è la lungezza impostata da te nel designer.

1686142138458.png
 
Top