0

I have emulator with 480x800 resolution and density 1,5. So when I display any ad (admob, madvertise) with 320x50 resolution in the view it is scaled to 480 x 75.

This is how the layout looks like - the ad views are added with code into LinearLayout (id adsholder):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.sbcgames.sbcengine.SBCGLView
        android:id="@+id/sbcglview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/adsholder"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical" >
    </LinearLayout>
</FrameLayout>

Is there any way how to prevent scaling? I would like to keep the original pixel dimensions instead of idp. I tried to add this into manifest but it did not help:

 <supports-screens android:anyDensity="true" />

Thanks for help

7
  • Are you displaying your ads in a WebView?
    – wsanville
    Oct 24, 2012 at 17:29
  • Put the size on the width and height instead of wrap_content, using px and not dp Oct 24, 2012 at 17:34
  • No, for admob it is com.google.ads.AdView and for Madvertise it is de.madvertise.android.sdk.MadvertiseView - it is created by code and then added into my LinearLayout that is wraping the ads size.
    – Tom Atom
    Oct 24, 2012 at 17:36
  • @nininho - I tried to set fixed size but I only got the ad cut. The ad inside the view was not scaled.
    – Tom Atom
    Oct 24, 2012 at 17:37
  • You could try then having a fixed size on the ad layoutparams instead of the parent linearlayout Oct 24, 2012 at 18:50

1 Answer 1

1

You have to enforce view (layout/image etc) size in real pixles (px). So:

<LinearLayout
    android:id="@+id/adsholder"
    android:layout_width="200px"
    android:layout_height="200px"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical" >
</LinearLayout>

will always be 200x200 pixels, no matter of screen density. See docs on the available units.

2
  • I tired this but it only cut the ad in the view - inside of it there is part of density-scaled ad visible.
    – Tom Atom
    Oct 24, 2012 at 17:49
  • It works as it should because container units are NOT inherited by its children. Then check your ad SDK to see if there's any API to control that. Alternatively you could traverse all children of your adsholder layout and modify its LayoutParams, but my guess is that this would cause other problems. Oct 24, 2012 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.