Android Question Layout shift down API36

ilan

Expert
Licensed User
Longtime User
hi

after the last update i am trying to update all my apps. many old apps do not use b4xpages and i encounter a strange behavior. after 1-2 sec of the app loading the whole ui shifts down.

i think it has something to do with the adviews (admob)

if i remove this lines the ui stays at its position.

B4X:
    'Admob
    Dim size As AdSize = GetAdaptiveAdSize
    iAd.Initialize("iad","ca-app-pub-xxxxxxxxxxxxxx/xxxxxx")
    Adview1.Initialize2("Adview1", "ca-app-pub-xxxxxxxxxxxxxx/xxxxxx", size.Native)' Adview1.SIZE_SMART_BANNER)
    Adview2.Initialize2("Adview2", "ca-app-pub-xxxxxxxxxxxxxx/xxxxxx", size.Native)' Adview2.SIZE_SMART_BANNER)
 
   ->   If Starter.isShabbat = False And Starter.isFullVersion = False Then
    ->        iAd.LoadAd'
    ->         Adview1.LoadAd
    ->         Adview2.LoadAd
    ->           settingstop.AddView(Adview1, 0,0,size.Width, size.Height)'100%x,height)
   ->          page2top.AddView(Adview2,0,0,size.Width, size.Height)'100%x,height)
   ->      End If

    If auth.CurrentUser.IsInitialized Then auth_SignedIn(auth.CurrentUser)
End Sub

Sub GetAdaptiveAdSize As AdSize
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim AdSize As JavaObject
    Dim width As Int = 100%x / GetDeviceLayoutValues.Scale
    Dim res As AdSize
    res.Native = AdSize.InitializeStatic("com.google.android.gms.ads.AdSize").RunMethod("getCurrentOrientationAnchoredAdaptiveBannerAdSize", Array(ctxt, width))
    Dim jo As JavaObject = res.Native
    res.Width = jo.RunMethod("getWidthInPixels", Array(ctxt))
    res.Height = jo.RunMethod("getHeightInPixels", Array(ctxt))
    Return res
End Sub

but even with those lines removed when the interstitial add is shown and the app returns the ui shifts again. if i leave those lines it happens even before the interstitial ad is shown.

can anyone give me a hint?

thanks


it is hard to see in the video because youtube auto crop it so i upload a screenshots. you can see that the buttons are now behind the navigationbar

1787521492695.png
 
Last edited:

ilan

Expert
Licensed User
Longtime User
Are you unaware about the Edge to edge in new versions of Android?
https://www.b4x.com/android/forum/pages/results/?query=edge+to+edge
thanks for your reply,

actually, i am aware of the new E2E feature and what i did is adding in main activity:

B4X:
#EdgeToEdgeOldDevices: True

and i load the layout like this:


B4X:
    ime.Initialize("ime")
    root = xui.CreatePanel("")
    Dim Content As Rect = ime.GetContentRect
    Log(Content)
    Activity.AddView(root, Content.Left, Content.Top, Content.Width, Content.Height)
    ime.UpdatePercentageReference(root.Width, root.Height)
    root.LoadLayout("Main")
    'Activity.LoadLayout("Main")

with b4xpages i dont need to do anything they work straight ahead with old apps i managed to make some work but some i have this strange behavior.
it has something to do with the admob full screen ad or maybe exiting and returning to the activity but i have no code that may shift the UI as far as i understand.

you can see that in the beginning the app loads correctly but after 1-2 seconds it shifts down.
if i remove the adviews code it stays in place but after the interstitial ad is shown and the app returns back after you close the ad the layout is shifted again.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
you can see that in the beginning the app loads correctly but after 1-2 seconds it shifts down.
if i remove the adviews code it stays in place but after the interstitial ad is shown and the app returns back after you close the ad the layout is shifted again.
Could you upload a small project for this issue?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Could you upload a small project for this issue?
its a huge project. i will need to see if i can reproduce it in a small project because in other project that also are not b4xpages it is working fine.
 
Upvote 0

tuhatinhvn

Active Member
Licensed User
Longtime User
I think this code is not correct:
-> settingstop.AddView(Adview1, 0,0,size.Width, size.Height)'100%x,height)
-> page2top.AddView(Adview2,0,0,size.Width, size.Height)'100%x,height)

Can you try with?
BannerAds.Initialize2("Bannerads", BannerAdsUnit, BannerAds.SIZE_BANNER)
root.AddView(BannerAds,(100%x-320dip)/2, pnlheader.GetBase.Height, 320dip, 50dip)
BannerAds.LoadAd
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i managed to fix the UI shifting by switching from SlidingMenuWrapper to B4XDrawer (don't know why but after switching it stopped shifting). this fixed the issue with the UI shift after you exit and return to the app but i still had a gap on the top part of the activity. even though i am using FULLSCREEN = TRUE it seems not to be loaded in fullscreen like it would try to show the statusbar. (but no statusbar is shown)

logging the "ime.GetContentRect" i noticed that the top is not 0 it returns 100 for some reason.


B4X:
    Dim Content As Rect = ime.GetContentRect
    Log(Content)

(Rect)(0, 100, 1080, 2205)

so what happened is the root panel was added with that top value:

B4X:
    ime.Initialize("ime")
    root = xui.CreatePanel("")
    Dim Content As Rect = ime.GetContentRect
    Log(Content)
    Activity.AddView(root, Content.Left,Content.Top, Content.Width, Content.Height)

and this is why i got the gap i dont know where this value comes from. i followed all tutorials and examples but still this is what i got only in this app.
my guess is that it has something to do either with TABSTRIP or ULV.

this is maybe the only app where i use ULV, all new apps i switched to CLV maybe @Informatix needs to update his ULV library, but still i am not sure if that is the problem or not. Anyway i fixed it like this:

B4X:
    Activity.AddView(root, Content.Left,0, Content.Width, Content.Height+Content.Top)

i tested it on several phones and it seems to fix the issue.

btw this is the tabstrip snipped i have in manifest:


B4X:
'********* TabStrip ***********************
CreateResource(drawable, background_tab.xml,
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:exitFadeDuration="@android:integer/config_shortAnimTime">
    <item android:state_pressed="true" android:drawable="@color/background_tab_pressed" />
    <item android:state_focused="true" android:drawable="@color/background_tab_pressed"/>
    <item android:drawable="@android:color/transparent"/>
</selector>)
CreateResource(values, colors.xml,
<resources>
    <color name="background_tab_pressed">#6633B5E5</color>
</resources>)
'******************************************

may this code effect the ime.recttop to return 100? or could it be related to ULV?
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
How many activities are there in your app?
B4X:
    Activity.AddView(root, Content.Left,0, Content.Width, Content.Height+Content.Top)
I think this is just an alternative solution. and the root cause of the issue is not related to ULV.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
How many activities are there in your app?
B4X:
    Activity.AddView(root, Content.Left,0, Content.Width, Content.Height+Content.Top)
I think this is just an alternative solution. and the root cause of the issue is not related to ULV.

1 activity. many years ago before b4xpages was introduced i created my apps using 1 activity and panels that loads the different layouts because i noticed the issue with managing multiple activities. Erel then introduced b4xpages that basically does the same.

i am sure that the SlidingMenuWrapper library caused the shifting after exiting and returning to the app because i could reproduce it but i still could not figure out why the ime rect returns a value and not 0 for the rect top. it looks like ULV or Tabstrip tell the activity to leave a gap on top and this is why the value is not 0 what leaves the empty space.

my solution will work even if ime rect top is 0 or higher so this is what i am using right now and it solved the issue. for other apps that dont use ULV or Tabstrip i am getting 0 for the rect top and everything works fine with using the already introduced fix for the E2E (using a root panel and loading everything to it)
 
Upvote 0
Top