0

I have a problem with supporting multiple screens with developing an android app.

Firstly, I made some layout design with the file activity_main.xml. I never used AbsoluteLayout and only used LinearLayout. Plus, some layouts I used fill_parent, match_parent, wrap_content, and dp. (Probably, using dp is the problem?)

Secondly, I made folders and copied activity_main.xml file in each folder.

res/layout/activity_main.xml

res/layout-small/activity_main.xml

res/layout-large/activity_main.xml

res/layout-xlarge/activity_main.xml

res/layout-xlarge-land/activity_main.xml

Lastly, I added these codes in the manifest file.

<compatible-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="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="large" android:screenDensity="ldpi" />
        <screen android:screenSize="large" android:screenDensity="mdpi" />
        <screen android:screenSize="large" android:screenDensity="hdpi" />
        <screen android:screenSize="large" android:screenDensity="xhdpi" />

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

I tested it on my Samsung Galaxy Note which I bought in South Korea, the layout does not fit in entire screen.

Can anyone help me how to fix this problem?

4

1 回答 1

2

你在这里做的太多了!!

如果每次都完全相同,则无需在不同文件夹中复制布局。

从头开始。删除清单中的整个 compatible-screens 部分。

从一个没有限定符的布局开始,并且仅在您尝试解决特定问题(您无法通过调整初始布局来解决)时创建新布局。

您似乎只在一部手机(旧的 Galaxy Note 1)上测试了这种布局,甚至还没有尝试在多部手机上测试它。通常,先让它在一个屏幕上运行,然后再尝试让它在多个屏幕上运行。

可以使用 dps 代替 wrap_content 或 fill_parent 等相对值,只需尝试在填充、边距和 minHeight/minWidth 中使用 dps,然后再尝试在 Width 和 Height 中使用它们。并尝试使用重力、重量或相对布局,以尽量减少使用 dps 对太多属性进行硬编码。

此外,尝试使用九个补丁 (.9.PNG) 而不是直接的 PNG。

最终,您将要学习使用布局设计器预览所有屏幕功能(Android Studio 中的功能,但现在甚至 Eclipse 也具有相同的功能)。

如果您想在布局中同时支持平板电脑和手机,请务必尝试使用片段。

于 2014-05-10T05:36:27.303 回答