【问题标题】:Compatibility mode between phone and tablet手机和平板的兼容模式
【发布时间】:2012-06-06 01:02:30
【问题描述】:
看完“屏幕兼容模式”documentation后我很困惑。首先,我创建了同一张图片的两种不同尺寸。其次,我只创建了一个布局。第三,我为我的图像设置了 150dip。最后,我在我的 Galaxy SII(高密度)中得到了正确的结果,但是当我模拟 Tablet 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>
我该怎么办?
【问题讨论】:
标签:
android
android-layout
android-emulator
【解决方案1】:
您应该在 res 中创建另一个文件夹 value-xlarge 来存储维度值。所以 XML 代码应该是:
layout.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>
values/dimens.xml:
<resources>
<dimen name="default_width">75dip</dimen>
<dimen name="default_height">75dip</dimen>
</resources>
values-xlarge/dimens.xml:
<resources>
<dimen name="default_width">150dip</dimen>
<dimen name="default_height">150dip</dimen>
</resources>
因此,当安装 apk 时,它将为正确的设备使用正确的尺寸值。 drawable 也是如此,如果需要,您可以创建 drawable-xlarge 来存储平板电脑的图像。