【发布时间】:2014-06-22 01:49:44
【问题描述】:
背景
我正在为一个 android 应用程序创建一个布局,并且到目前为止一直使用以sp(或dp)表示的字体大小,以便它们可以针对不同的设备正确缩放。然而结果与我所希望的不同。结果是文本在所有设备上都是相同的物理大小(以英寸为单位),而我希望它占据屏幕的相同比例。
目前,我的菜单按钮在平板电脑上看起来有点小,但在手机上却大得离谱(请参阅屏幕截图;虽然它并不能说明手机版本看起来有多糟糕)。
使用px 实际上为我提供了我想要的这些特定设备的结果,但那是因为它们具有相似的分辨率(但像素密度非常不同)。如果我根据我希望它在这两个设备上的外观(均约为 1,200 x 700)使用像素,并且 Galaxy S10 的物理尺寸与 Galaxy S3 相同,但分辨率为 10,000 x 7,000,那么我的按钮看起来会小得离谱。
问题
如何设置与分辨率无关(与密度无关)的字体大小(或任何大小)?
Galaxy S3 - 大号手机
标签 3 - 中等平板电脑
当前布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/menubackground"
>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/singleplayer"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:textSize="50sp"
android:onClick="singleplayer"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/twoplayer"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:textSize="50sp"
android:onClick="twoplayer"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/campaign"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:textSize="50sp"
android:onClick="campaign"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/ai_vs_ai"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:textSize="50sp"
android:onClick="aiVsAI"
/>
</LinearLayout>
</LinearLayout>
【问题讨论】:
标签: java android resolution