我想知道如何使不同设备上的应用程序看起来相同。我读过很多次书,但我还是不懂如何生活。
以下是布局示例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Hello World, MyActivity"
            android:textSize="30sp"
            />
</LinearLayout>

有Galaxy S II(480x800)和Sensation XE(540x960)。它们都是hdpi,物理屏幕大小几乎相同。我希望在两个设备上看到相同的外观,但实际上540x960上的文本比480x800上的小:
(左为480x800,右为540x960)
我试图将文本大小指定为维度资源,并创建单独的文件夹values-w540dp,但没有效果。
你们如何使你们的应用程序在不同的hdpi设备上看起来相同?

最佳答案

android:textAppearance="?android:attr/textAppearanceLarge"

android:textAppearance="?android:attr/textAppearanceMedium"

android:textAppearance="?android:attr/textAppearanceSmall"

这些属性可以解决您的问题,否则您必须使用屏幕的高度和宽度动态设置布局,并使用某些比率(或您生成的因子,如:textsize=factor*height)。

07-24 09:51
查看更多