Android Question [Solved] Problem with Admob-Height

D

Deleted member 103

Guest
Hi,

this code does not work properly on my Nokia 7.1, because the banner is cut off (see pictures).
So that it is correctly displayed correctly on the Nokia, I have to change the height to 90dip, is this normal?

B4X:
Adview1.Initialize2("Ad", "xxxxxxxx", AdView1.SIZE_SMART_BANNER)
Dim height As Int
    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
       'phones
       If 100%x > 100%y Then height = 32dip Else height = 50dip
   Else
       'tablets
       height = 90dip
   End If
   Activity.AddView(AdView1, 0dip, 100%y - (toolbar.height + height), 100%x, height)

Correct presentation at HTC-one.
b4a_01.png


Wrong presentation on Nokia 7.1
b4a_02.png

 

Sagenut

Expert
Licensed User
Longtime User
@Filippo
Did You checked the Scale of the displays?
Can it be that one is in Scale 1.0 and the other one is Scale 1.5?
 
Upvote 0
D

Deleted member 103

Guest
It works well for me. I use a panel as base, set its top and height based on the height of the banner (which depends on the device) and then load the layout into this base panel.
The solution with a panel brings no change!
You have to change the banner height to 90dip so that it is displayed correctly on Nokia devices.
 

Attachments

  • banner_50dip.png
    banner_50dip.png
    243.8 KB · Views: 231
  • banner_90dip.png
    banner_90dip.png
    232.7 KB · Views: 244
Upvote 0
D

Deleted member 103

Guest
@Filippo
Did You checked the Scale of the displays?
Can it be that one is in Scale 1.0 and the other one is Scale 1.5?
I have different devices with different scale. Everywhere it works without problems, only with Nokia the banner height is wrong.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
In the link it show that the device has Soft Keys.
I got problem detecting screen size because of that.
I solved with ImmersiveMode but it could not be what you want for your app.
Does Nokia have Soft Keys?
 
Upvote 0
D

Deleted member 103

Guest
Many thanks @Pendrush!
That's exactly what I need.
I have optimized your code a bit.
B4X:
...
Activity.AddView(BannerAd, 0dip, 100%y - GetAddViewHeight , 100%x, GetAddViewHeight)
...

Public Sub GetAddViewHeight As Int
    Dim AdMobHeight As Int

    If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
        Dim ScreenHeightScaled As Float
        ScreenHeightScaled = GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
        Log("ScreenHeightScaled=" & ScreenHeightScaled)
        ' Ad height 32dip: device screen height <= 400
        ' Ad height 50dip: 400 < device screen height <= 720
        ' Ad height 90dip: device screen height > 720
        If ScreenHeightScaled <= 400 Then
            AdMobHeight = 32dip
        Else if ScreenHeightScaled > 400 And ScreenHeightScaled <= 720 Then
            AdMobHeight = 50dip
        Else if ScreenHeightScaled > 720 Then
            AdMobHeight = 90dip
        End If
    Else
        If 100%y > 100%x Then
            'tablets
            AdMobHeight = 90dip
        Else
            AdMobHeight = 50dip
        End If
    End If

    Return AdMobHeight
End Sub
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
You don't need to change code, you already made a mess with
B4X:
 If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
as you will get false result on probably 10%-20% android devices.
Use original code, as original code is in use last two years in app with over 500k active installation, without any problem.
 
Upvote 0
D

Deleted member 103

Guest
You don't need to change code, you already made a mess with
B4X:
 If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
as you will get false result on probably 10%-20% android devices.
Use original code, as original code is in use last two years in app with over 500k active installation, without any problem.
You're right! The code down here is perfect.
B4X:
...
Activity.AddView(BannerAd, 0dip, 100%y - GetAddViewHeight , 100%x, GetAddViewHeight)
...

Public Sub GetAddViewHeight As Int
    Dim AdMobHeight As Int
    Dim ScreenHeightScaled As Float
    ScreenHeightScaled = GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
    ' Ad height 32dip: device screen height <= 400
    ' Ad height 50dip: 400 < device screen height <= 720
    ' Ad height 90dip: device screen height > 720
    If ScreenHeightScaled <= 400 Then
        AdMobHeight = 32dip
    Else if ScreenHeightScaled > 400 And ScreenHeightScaled <= 720 Then
        AdMobHeight = 50dip
    Else if ScreenHeightScaled > 720 Then
        AdMobHeight = 90dip
    End If
    Return AdMobHeight
End Sub
 
Upvote 0

tuhatinhvn

Active Member
Licensed User
Longtime User
Recent Admob has block some my apps because this problem, because admob banner is cropped!

Code of @Filippo is on code, but our bal file use designer, but on designer we cannot how to get admob height because:
ScreenHeightScaled = GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
can not work on desiger, anyone has idea??
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Public Sub GetAddViewHeight As Int
Dim AdMobHeight As Int
Dim ScreenHeightScaled As Float
ScreenHeightScaled =
GetDeviceLayoutValues.Height / GetDeviceLayoutValues.Scale
' Ad height 32dip: device screen height <= 400
' Ad height 50dip: 400 < device screen height <= 720
' Ad height 90dip: device screen height > 720
If ScreenHeightScaled <= 400 Then
AdMobHeight = 32dip
'***** Else if ScreenHeightScaled > 400 And ScreenHeightScaled <= 720 Then
Else if ScreenHeightScaled <= 720 Then
AdMobHeight = 50dip
'***** Else if ScreenHeightScaled > 720 Then
Else

AdMobHeight = 90dip
End If
Return AdMobHeight
End Sub
 
Upvote 0
Top