防止视图中的密度缩放

时间:2012-10-24 17:28:20

标签: android view scaling

我有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" />

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您必须以实际像素(px)强制执行视图(布局/图像等)大小。所以:

<LinearLayout
    android:id="@+id/adsholder"
    android:layout_width="200px"
    android:layout_height="200px"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical" >
</LinearLayout>
无论屏幕密度如何,

始终为200x200 像素。请参阅docs on the available units

相关问题