如何限制应用在平板电脑上工作?

时间:2013-05-01 19:59:37

标签: android

我正在为手机制作Android应用程序。我的用户界面未针对平板电脑进行优化,因此我不希望平板电脑用户使用它。如何限制我的应用在平板电脑上工作?

1 个答案:

答案 0 :(得分:3)

您必须使用清单中的<compatible-screens>元素明确声明您希望支持的屏幕尺寸和密度。

以下示例来自the documentation on this subject

<compatible-screens>
    <!-- all small size screens -->
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" />
    <!-- all normal size screens -->
    <screen android:screenSize="normal" android:screenDensity="ldpi" />
    <screen android:screenSize="normal" android:screenDensity="mdpi" />
    <screen android:screenSize="normal" android:screenDensity="hdpi" />
    <screen android:screenSize="normal" android:screenDensity="xhdpi" />
</compatible-screens>

请注意,该示例存在缺陷,因为它会阻止您的应用出现在-xxhdpi设备上(例如,SONY Xperia Z,Droid DNA)。您还需要为<screen>添加另一对xxhdpi元素,以涵盖该情景:

<compatible-screens>
    <!-- all small size screens -->
    <screen android:screenSize="small" android:screenDensity="ldpi" />
    <screen android:screenSize="small" android:screenDensity="mdpi" />
    <screen android:screenSize="small" android:screenDensity="hdpi" />
    <screen android:screenSize="small" android:screenDensity="xhdpi" />
    <screen android:screenSize="small" android:screenDensity="xxhdpi" />
    <!-- all normal size screens -->
    <screen android:screenSize="normal" android:screenDensity="ldpi" />
    <screen android:screenSize="normal" android:screenDensity="mdpi" />
    <screen android:screenSize="normal" android:screenDensity="hdpi" />
    <screen android:screenSize="normal" android:screenDensity="xhdpi" />
    <screen android:screenSize="normal" android:screenDensity="xxhdpi" />
</compatible-screens>