与多屏幕支持相关的布局问题

发布于 2024-10-01 22:42:14 字数 1822 浏览 0 评论 0原文

我正在尝试开发一个需要多屏幕支持的应用程序。我已阅读有关多屏幕支持最佳实践的 Android 文章。根据本文,我们必须遵循 3 件重要的事情:

  1. 在 AndroidManifest.xml 中提及对不同屏幕尺寸(大、中、小)和任何密度的支持。
  2. 将 3 dpi(120、160、240)的图像放置在 3 个文件夹 res/ldpi、res/mdpi 和 res/hdpi 中。
  3. 在布局中,尺寸应以“倾角”单位提及。然后 Android 将自行处理缩放。

我已经在我的项目中实现了所有这些要点。图像是从适当的文件夹中正确拾取的。但控制的安排并不相同。

例如,我在三个模拟器上运行该应用程序


1。分辨率240*320 dpi 120。
2。分辨率240*320 dpi 160。
3。分辨率240*320 dpi 240。
(所有模拟器具有相同的分辨率但不同的密度。)

问题是控件的位置在所有三个模拟器上都不相同。根据我的理解,如果 android:layout_marginLeft 和 android:layout_marginTop 在“dip”中提到,那么这个问题不应该发生。随着模拟器密度的增加,控件会更加靠右放置。

即使所有设备的布局都相同,我是否绝对有必要为屏幕尺寸和密度的所有组合提供布局?

我是否遗漏了一些重要的观点?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <ImageView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:src="@drawable/bgd" android:scaleType="fitXY">
    </ImageView>
   <ImageView android:id="@+id/wtButton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/button" android:layout_marginLeft="170dip"
        android:layout_marginTop="9dip"></ImageView>
    <ImageView android:id="@+id/htButton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/button2" android:layout_marginLeft="220dip"
        android:layout_marginTop="90dip"></ImageView>
</RelativeLayout>

图片:

https://docs.google.com/leaf?id=0By3GYC3k5AMDNzUwNjkwMWEtOGQzZC00MjQ0LWE2OTgtYjFhYzZmM2ExOGVl&hl=en&authkey=CLOEsZsI

I am trying to develop an app for which I want multiple screen support. I have read the Android article on Best practices for Multiple Screen Support. As per the article we have to follow 3 important things:

  1. Mention support for different screen sizes(large, medium and small) and any density in AndroidManifest.xml.
  2. Place images of 3 dpi's (120, 160, 240) in 3 folders res/ldpi, res/mdpi and res/hdpi.
  3. In layout's the dimension should be mentioned in "dip" units. Then Android will take care of the scaling on its own.

I have implemented all these points in my project. The images are picked up correctly from the appropriate folders. But the arrangements of the controls in not same.

e.g. I ran the app on three emulators

1. Resolution 240*320 dpi 120.

2. Resolution 240*320 dpi 160.

3. Resolution 240*320 dpi 240.

(All the emulator have same resolution but different density. )

The problem is the position of the controls is not same on all the three emulator. As per my understanding if the android:layout_marginLeft and android:layout_marginTop are mentioned in "dip" then this problem should not occur. As the density of the emulator increases the controls get placed more towards the right.

Is it absolutely necessary that i provide layouts for all combination's of screen dimension and density even if the layout is same for all the devices?

Am I missing some important point?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <ImageView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:src="@drawable/bgd" android:scaleType="fitXY">
    </ImageView>
   <ImageView android:id="@+id/wtButton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/button" android:layout_marginLeft="170dip"
        android:layout_marginTop="9dip"></ImageView>
    <ImageView android:id="@+id/htButton"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:src="@drawable/button2" android:layout_marginLeft="220dip"
        android:layout_marginTop="90dip"></ImageView>
</RelativeLayout>

Images:

https://docs.google.com/leaf?id=0By3GYC3k5AMDNzUwNjkwMWEtOGQzZC00MjQ0LWE2OTgtYjFhYzZmM2ExOGVl&hl=en&authkey=CLOEsZsI

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

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

发布评论

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

评论(3

淡淡的优雅 2024-10-08 22:42:14

是的,您必须在清单文件中添加以下内容,然后它才会采取
根据需要从 ldpi、mdpi、orhdpi 获取资源

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

    <compatible-screens>
 <screen
            android:screenDensity="mdpi"
            android:screenSize="mediaum" />      
  <screen
            android:screenDensity="hdpi"
            android:screenSize="large" />
        <screen
            android:screenDensity="xhdpi"
            android:screenSize="large" />
    </compatible-screens>

Yes you have to ADD the following thing in the manifest file then only it will take the
Resorces from the ldpi,mdpi,orhdpi as per need

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

    <compatible-screens>
 <screen
            android:screenDensity="mdpi"
            android:screenSize="mediaum" />      
  <screen
            android:screenDensity="hdpi"
            android:screenSize="large" />
        <screen
            android:screenDensity="xhdpi"
            android:screenSize="large" />
    </compatible-screens>
寻找我们的幸福 2024-10-08 22:42:14

首先计算设备高度和宽度

,然后如果您想将视图的 leftpadding 值设置为 180,将 toppadding 值设置为 48,则将其设置为

(320 /1.8 = 1.77)

meterView.setPadding((int) (width/1.8), (int ) (高度/10), 3, 5);

试试这个。

First you calculate device height and width

then if u want set 180 as leftpadding value and 48 as toppadding value for view, then set it as

(320 /1.8 = 1.77)

meterView.setPadding((int) (width/1.8), (int) (height/10), 3, 5);

try this.

挥剑断情 2024-10-08 22:42:14

问题是随着设备尺寸的增加,图像尺寸会减小。
相应地重新调整图像大小(增加 mdp 和 ldpi 图像的大小)。
如果你想以 Nexus 系列为目标,它总是以 Xhdpi 和 hdpi 为目标,这是一个真正的痛苦。
你也可以参考我这里的回答:
Android:支持多个屏幕

The problem is as the size of the devices increase your image size decrease.
Re-size your images accordingly (increase mdp and ldpi image's size).
If you wnat to target Nexus series, it would always target Xhdpi and hdpi, which is a real pain.
you can also refer to my answer here :
Android: support multiple screens

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