无法支持多种屏幕分辨率

发布于 2024-12-20 03:43:20 字数 2629 浏览 5 评论 0原文

我正在努力完成我的 Android 应用程序,但我在 UI 方面遇到了一些问题。我的问题非常基本,我在 Eclipse 中使用 AVD 管理器时使用默认 AVD 开发了 UI(HVGA,密度为 160 dpi),当我执行应用程序时,我看到它是我设计的,但如果我改变目标设备(即 WVGA 或 QVGA)布局中的所有组件都位于与原始设备不同的位置。据我在支持多屏幕的建议中看到,我不应该使用AbsoluteLayouts,事实上我正在使用RelativeLayouts,我没有使用“px”作为尺寸(或位置),只是“wrap_content”或“fill_parent” ”,如果我需要一个特定的位置,我会使用“dp”(也使用“sp”进行测试),而且我已经将图像缩放为 ldpi (0.75x),但仍然存在问题(不是特定的问题)屏幕,洞应用程序).​​..所以,我的问题是,是否还有我遗漏的其他 UI 提示?。
我提供了一个示例代码以及我在使用 HVGA AVD(更大的图像)和 QVGA AVD 对其进行测试时观察到的结果。正如您所看到的,黄色/绿色方块的位置不同,最后一行图像的大小也不同。
PS:我也使用TabLayout,因此背景是通过代码加载的(tabHost.setBackgroundDrawable(getResources().getDrawable(R.drawable.background1)))
任何帮助将不胜感激。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/row1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="140dp"
    >
    <ImageView
        android:id="@+id/btn1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button1"
    />
    <ImageView
        android:id="@+id/btn2"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button2"
    />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/row1"
        android:layout_centerHorizontal="true"
    >
    <ImageView
        android:id="@+id/btn3"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button3"
    />
    <ImageView
        android:id="@+id/btn4"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button4"
    />
    </LinearLayout>
</RelativeLayout>

屏幕分辨率 240x320 屏幕分辨率 320x480

I'm struggling to finish my Android app, but I'm having some problems with the UI. My problem is very basic, I've developed the UI using the default AVD when using AVD manager in Eclipse (HVGA, with a density of 160 dpi), and when I execute the app I see it as I designed, but if I change the target device (i.e. WVGA or QVGA) all the components in the layout are in a different position than the original. As far as I saw in the recommendations for support multiple screens, I should not use AbsoluteLayouts, in fact I'm using RelativeLayouts, I'm not using "px" for the dimensions (or positions), just "wrap_content" or "fill_parent", and in case I need an specific position I'm using "dp" (tested too with "sp"), also I've scaled the images for ldpi (0.75x), and still have the issue (not a particular screen, the hole app) ...so, my question is, is there any other UI tip that I'm missing?.
I'm putting a sample code and the results that I observe when testing it with a HVGA AVD (bigger image) and with a QVGA AVD. As you can see, the position of the yellow/green squares is different, as well as the size of the last row of images.
PS: I'm using a TabLayout also, so the background is loaded through code (tabHost.setBackgroundDrawable(getResources().getDrawable(R.drawable.background1)))

Any help will be appreciated.

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/row1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="140dp"
    >
    <ImageView
        android:id="@+id/btn1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button1"
    />
    <ImageView
        android:id="@+id/btn2"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button2"
    />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/row1"
        android:layout_centerHorizontal="true"
    >
    <ImageView
        android:id="@+id/btn3"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button3"
    />
    <ImageView
        android:id="@+id/btn4"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:onClick="method1"
        android:src="@drawable/button4"
    />
    </LinearLayout>
</RelativeLayout>

screen at 240x320
screen at 320x480

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

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

发布评论

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

评论(3

任性一次 2024-12-27 03:43:20

你的布局对我来说看起来很好,除了背景上有一个白色的框标题,因为它会让把东西放在它们的位置上变得更加困难。另外,RelativeLayout 没有方向,但会被忽略。

在更大的屏幕截图中,白框和屏幕顶部之间看起来有更多的空间。对我来说没有意义的是第二行的不同尺寸。您是否 100% 确定在较小的屏幕截图中加载了正确的图像?

Your layout looks fine to me, except for having that white box title on the background as it will make more difficult to put things in their position. Also, RelativeLayout does not have orientation but that is ignored.

In the bigger screenshot it looks like there is more space between the white box and the top of the screen. What it does not make sense to me is the different size in the second row. Are you 100% sure you are loading the correct images in the smaller screenshot?

八巷 2024-12-27 03:43:20

您需要为 diff 创建不同的布局。分辨率即对于大屏幕使用布局大文件夹..
我希望链接对您有所帮助。

You need to create different layout for diff. resolution i.e for large screen use layout-large folder..
I hope this link help to you.

若有似无的小暗淡 2024-12-27 03:43:20

您是否按照开发人员网站上给出的步骤使您的应用支持多个屏幕?

Did you follow the steps given on the developer site to make ur app to support multiple screens?

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