0

阅读“屏幕兼容模式”文档后,我很困惑。首先,我创建了同一张图片的两种不同尺寸。其次,我只创建了一个布局。第三,我为我的图像设置了 150dip。最后,我在我的 Galaxy SII(高密度)中得到了正确的结果,但是当我模拟平板电脑 10 英寸(中密度)时我没有得到正确的结果。查看两个设备中到右边框的距离。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="150dip"
    android:layout_height="150dip"
    android:text="DENSIDADE" />

<ImageView 
    android:id="@+id/image1"
    android:src="@drawable/mode_tapcolor"
    android:layout_width="150dip"
    android:layout_height="150dip" />

</LinearLayout>

Tablet 10 模拟器 三星盖乐世 SII

我应该怎么办?

4

1 回答 1

0

您应该在res中创建另一个文件夹value-xlarge来存储维度值。所以 XML 代码应该是:

布局.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button1"
    android:layout_width="@dimen/default_width"
    android:layout_height="@dimen/default_height"
    android:text="DENSIDADE" />

<ImageView 
    android:id="@+id/image1"
    android:src="@drawable/mode_tapcolor"
    android:layout_width="@dimen/default_width"
    android:layout_height="@dimen/default_height" />

</LinearLayout>

值/尺寸.xml:

<resources>
    <dimen name="default_width">75dip</dimen>
    <dimen name="default_height">75dip</dimen>
</resources>

值-xlarge/dimens.xml:

<resources>
    <dimen name="default_width">150dip</dimen>
    <dimen name="default_height">150dip</dimen>
</resources>

因此,当安装 apk 时,它将为正确的设备使用正确的尺寸值。drawable 也是如此,如果需要,您可以创建 drawable-xlarge 来存储平板电脑的图像。

于 2012-06-06T01:15:15.873 回答