Android 中的多屏幕支持

发布于 2024-12-05 11:04:54 字数 453 浏览 2 评论 0原文

我正在开发一个项目,并且已经在 Nexus One 上对其进行了测试。它在那里工作正常,但我希望我的项目应该与所有屏幕尺寸兼容。 如何做到这一点? 我已经

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

在 androidmainfest.xml 中给出了参数

I am working on a project and i have tested it on nexus one. its working there properly but I want that my project should be compatible with all screen sizes.
How to do this??
I have given

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

parameters in the androidmainfest.xml

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

給妳壹絲溫柔 2024-12-12 11:04:54

在过去,我们曾经为多个屏幕创建不同的布局文件夹,例如layout-small、layout-normal、layout-large、layout-xlarge。但这是一项艰巨的工作。所以就有了一种新的方式来支持多屏。详细信息如下。

用于支持多屏幕(所有手机和平板电脑):

对于手机:我们通常对不同的 dpi 使用不同的值文件夹,并且在该值文件夹内仅使用“dimens.xml”文件是不同的,因为当我们使用不同的设备时,除了所有参数(例如颜色、字符串、样式等)相同之外,仅尺寸发生变化。
对于值文件夹:共有 4 个值文件夹。

values                                    (For mdpi devices)
values-hdpi                               (For hdpi devices)
values-xhdpi                              (For xhdpi devices)
values-xxhdpi                             (For xxhdpi devices)

(这里每个文件夹内只有dimens文件不同,因此除了dimens文件外,所有其他文件仅保留在values文件夹中。)

对于平板电脑:我们必须使用sw(smallestWidth)概念。例如sw600dp意味着只有当可用屏幕的最小尺寸至少为600dp时系统才会使用这些资源。当屏幕方向改变时,设备的smallestWidth不会改变。
一般来说,我们在平板电脑的 res 文件夹中创建两个文件夹:

layout-sw600dp                       (For 7″ to 9″ Screen)
layout-sw720dp                       (For 10″ to above screen)

最后一件事,对于任何设备(手机或平板电脑)的图像,您必须创建不同的可绘制文件夹:

drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi

For Old day, we used to create different layout folder such as layout-small, layout-normal, layout-large, layout-xlarge for multiple screen. But that is a hell lot of work. So there is a new way to support multiple screen. Details are given below.

For Support Multiple Screen (All Mobiles and Tablets):

For Mobiles : We generally using different values folders for different dpi and inside that values folders only the “dimens.xml” file is different because when we are using different devices only the dimension is changed other than that all the parameters for example colors, strings, styles etc. are same.
For values folders: There are total 4 values folders.

values                                    (For mdpi devices)
values-hdpi                               (For hdpi devices)
values-xhdpi                              (For xhdpi devices)
values-xxhdpi                             (For xxhdpi devices)

(here Inside each folder only dimens file is different so except dimens file, keep all other files only in values folder.)

For Tablets : We have to use sw (smallestWidth) concept. For example sw600dp means the system will use these resources only when the smallest dimension of available screen is at least 600dp. The device’s smallestWidth does not change when the screen’s orientation changes.
Generally we create two folders inside res folder for tablets:

layout-sw600dp                       (For 7″ to 9″ Screen)
layout-sw720dp                       (For 10″ to above screen)

One last thing, Images for any device (Mobiles or Tablets) you have to create different drawable folders:

drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
不交电费瞎发啥光 2024-12-12 11:04:54

http://developer.android.com/guide/practices/screens_support.html

您必须在 res 文件夹中为不同的布局添加不同的文件夹 --> hdpi、mdpi、ldpi,对于大屏幕,您可以选择 xhdpi(适用于平板电脑)和 large-hdpi 或 xlarge(适用于 NXzoom)。还根据屏幕尺寸在不同布局中设置不同的图像和文本大小...

http://developer.android.com/guide/practices/screens_support.html

You have to add different folder for different layout in res folder --> hdpi,mdpi,ldpi and for large screens you xhdpi(for Tablet) and large-hdpi or xlarge (for NXzoom). Also set Images and text size different in different layout as per screensize...

十六岁半 2024-12-12 11:04:54

我正在以这种方式处理它,并且工作正常......如果有人有改进的方法,请指导我

屏幕尺寸480x800

布局-正常-hdpi-480x800

可绘制-正常-hdpi-480x800

屏幕尺寸 Galaxy Nexus--- 虽然其尺寸为 1280x720,但实际上由于系统栏的原因,其尺寸(屏幕尺寸)与

布局-正常-xhdpi

不同drawable-normal-xhdpi

屏幕尺寸注5.3---

layout-normal-xhdpi-1280x800drawable

-normal-xhdpi-1280x800

屏幕尺寸S3---

layout-normal- xhdpi-1280x720

drawable-normal-xhdpi-1280x720

屏幕尺寸 7inch tab 2 支持操作系统版本3及以上---实际不要写尺寸1026x600 bsz,因为系统栏其尺寸(屏幕尺寸)不同

布局-大-mdpi

可绘制-大-mdpi

屏幕尺寸7inch tab p1000等支持操作系统版本小于3---

layout-large-hdpi-1024x600drawable

-large-hdpi-1024x600

屏幕尺寸1280x800 选项卡 10.1,10.2,note 10.1 等 --- 如果您愿意,您可以添加尺寸,否则它是很好的

布局-xlarge-mdpi

可绘制-xlarge-mdpi

i am dealing with it this way and its working fine.....if any one has improved wayso do guide me

Screen size 480x800

layout-normal-hdpi-480x800

drawable-normal-hdpi-480x800

Screen size Galaxy Nexus--- though its size is 1280x720 but in actual due to system bar its dimension(screen size) differs

layout-normal-xhdpi

drawable-normal-xhdpi

Screen size Note 5.3---

layout-normal-xhdpi-1280x800

drawable-normal-xhdpi-1280x800

Screen size S3---

layout-normal-xhdpi-1280x720

drawable-normal-xhdpi-1280x720

Screen size 7inch tab 2 supporting OS version 3 and above--- dont write dimension 1026x600 bsz in actual due to system bar its dimension(screen size) differs

layout-large-mdpi

drawable-large-mdpi

Screen size 7inch tab p1000 etc supoorting os verion less than 3---

layout-large-hdpi-1024x600

drawable-large-hdpi-1024x600

Screen size 1280x800 tab 10.1,10.2,note 10.1 etc--- you can add dimension if you want other wise it is fine

layout-xlarge-mdpi

drawable-xlarge-mdpi

桜花祭 2024-12-12 11:04:54

上面的所有答案都有自己的方法。很多时候,考虑到一些复杂的布局线,我们在 RelativeLayout 中嵌套的 LinearLayout 很难适应所有屏幕Tile

上述场景可以通过android的百分比支持库适配所有屏幕来解决。

此处演示

GitHub 项目此处

<android.support.percent.PercentRelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/fifty_huntv"
        android:background="#ff7acfff"
        android:text="20% - 50%"
        android:textColor="@android:color/white"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_heightPercent="20%"
        app:layout_widthPercent="50%" />
    <TextView
        android:layout_toRightOf="@id/fifty_huntv"
        android:background="#ffff5566"
        android:text="80%-50%"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_heightPercent="80%"
        app:layout_widthPercent="50%"
        />
</android.support.percent.PercentRelativeLayout>

简单演示示例

希望有人觉得它有用:-)。

All the answers above are great in there own means.Many times we're in scenario where our nested LinearLayout within RelativeLayout is hard to fit all the screens considering some complex layout line Tile

The above scenario can be solved by android's percent support library fitting all the screens.

Demo HERE

GitHub Project HERE

<android.support.percent.PercentRelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/fifty_huntv"
        android:background="#ff7acfff"
        android:text="20% - 50%"
        android:textColor="@android:color/white"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_heightPercent="20%"
        app:layout_widthPercent="50%" />
    <TextView
        android:layout_toRightOf="@id/fifty_huntv"
        android:background="#ffff5566"
        android:text="80%-50%"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_heightPercent="80%"
        app:layout_widthPercent="50%"
        />
</android.support.percent.PercentRelativeLayout>

Simple example for demo

Hope anyone find it useful :-).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文