2012-10-24 39 views
0

我擁有480x800分辨率和密度1.5的模擬器。因此,當我在視圖中顯示320x50分辨率的任何廣告(admob,madvertise)時,它將縮放爲480 x 75.阻止視圖中的密度縮放

這就是佈局的樣子 - 廣告視圖添加了代碼到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> 

有沒有辦法如何防止縮放?我想保留原始像素尺寸而不是idp。我試圖加入到這個清單,但它並沒有幫助:

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

感謝您的幫助

+0

您是否在「WebView」中顯示您的廣告? – wsanville

+0

把大小的寬度和高度,而不是wrap_content,使用px而不是dp –

+0

不,對於admob它是com.google.ads.AdView和Madvertise它是de.madvertise.android.sdk.MadvertiseView - 它被創建通過代碼,然後添加到我的LinearLayout包裝廣告大小。 –

回答

1

你必須強制視圖(佈局/圖像等)大小在現實pixles(px)。所以:

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

將永遠是200×200像素,沒有屏幕像素密度的問題。見docs on the available units

+0

我厭倦了這一點,但它只是在視圖中剪切了廣告 - 它內部是密度縮放廣告的一部分。 –

+0

它的工作原理應該如此,因爲容器單位不會被其子女繼承。然後檢查您的廣告SDK,看看是否有任何API來控制它。或者,你可以遍歷你的'adsholder'佈局的所有孩子,並修改它的LayoutParams,但我的猜測是這會導致其他問題。 –