简体   繁体   English

支持多屏(手机和平板电脑)

[英]Supporting Multiple Screens (phone and tablet)

I am beginner to programming for android. 我是android编程的初学者。 First of all i need that my app will be supported by 2 devices phone (480x800) and tablet (1280x800). 首先,我需要2种设备的手机(480x800)和平板电脑(1280x800)支持我的应用。

I read this and tried to do step by step. 我读了这篇,并试图一步一步地做。 Supporting Multiple Screens 支持多屏

So i created folders with layouts: 所以我用布局创建了文件夹:

res/layout/firstPage.xml//this is by default phone layout port and land
res/layout-sw720dp/firstPage.xml//this is tablet port layout
res/layout-sw720dp-land/firstPage.xml//this is tablet land layout

My xml looks like this: 我的xml看起来像这样:

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

    <Button
        android:id="@+id/button1"
        android:text="@string/button1" />

    <Button
        android:id="@+id/button2"
        android:text="@string/button2" />

    <Button
        android:id="@+id/button3"
        android:text="@string/button3" />

</LinearLayout>

I don't give more info about button because in every layout they are different. 我没有提供有关按钮的更多信息,因为在每种布局中它们都是不同的。

In my AndroidManifest.xml i have this line: 在我的AndroidManifest.xml中,有以下一行:

<supports-screens android:anyDensity="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:largeScreens="true"/>

Maybe i don't need to set true for others if i set tru to this anyDensity="true" 如果我将tru设置为anyDensity =“ true”,也许我不需要为其他人设置true

So i think i did everything as i should. 所以我认为我尽了一切。 But when i wanted to test on tablet it shows me layout by default of phone. 但是,当我想在平板电脑上测试时,默认情况下会显示我的手机布局。 So what i missed ? 那我错过了什么? Or i need to do some coding also ? 或者我还需要做一些编码?

Edited: 编辑:

I think i understand why... Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier to define the smallest available width required by your layout resources. 我想我明白为什么...从Android 3.2(API级别13)开始,不建议使用上述大小组,而应使用swdp配置限定符定义布局资源所需的最小可用宽度。

My table is 3.1 so that why it didn't find layout ? 我的桌子是3.1,所以为什么找不到布局? But what to do if i want to support from 2.1 to 4 ? 但是,如果我想支持2.1到4,该怎么办?

Sollution: 解决方法:

You Should have to follow: Best Practise 您应该遵循: 最佳实践

Try to use the different layout for different screen size: 尝试对不同的屏幕尺寸使用不同的布局:

As like: 像:

res/layout/my_layout.xml         // layout for normal screen size ("default")res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

Use Different size of images as per the different Screen Size of device: 根据设备的不同屏幕尺寸使用不同尺寸的图像:

As Like: 像:

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

Still if its not solve your problem then use the static size for the images for respective different layout. 仍然,如果不能解决您的问题,请为各个不同的布局使用图像的静态大小。

As per my point of view and the Document it self explain that you should have to follow certain steps to do this. 根据我的观点和文档,它自我说明您必须执行某些步骤。

Hope it will helps you. 希望对您有帮助。 nd if not then let me know where you getting stop in managing layout. 如果没有,请告诉我您在管理版式方面遇到的困难。

Thanks. 谢谢。

the layout-sw720p only works in 3.2 and after android versions and not on 3.0 and 3.1 layout-sw720p仅适用于3.2及更高版本的android,不适用于3.0和3.1

Hope this helps here is the link http://developer.android.com/guide/practices/screens_support.html Under Using new size qualifiers --> Table 2. New configuration qualifers for screen size (introduced in Android 3.2). 希望这对您有所帮助,链接为http://developer.android.com/guide/practices/screens_support.html在“使用新的大小限定符->表2”下。屏幕大小的新配置限定符(在Android 3.2中引入)。

try using this... 尝试使用这个...

res/layout/firstPage.xml//this is by default phone layout port and land
res/layout-xlarge/firstPage.xml//this is tablet port layout
res/layout-xlarge-land/firstPage.xml//this is tablet land layout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM