我有我的Android应用程序的问题。当我使用我的惠普触摸板,其分辨率为1024x768,一切看起来都不错。然而,当我测试了一个800×480(Desire HD的)这个事情发生了: 不同的屏幕分辨率显示在平板电脑(1024×768)好,但坏的手机(800×480)
这里是我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayoutH1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="vertical"
android:weightSum="1" >
<EditText
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_weight=".50"
/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_weight=".50"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutH3"
android:layout_width="fill_parent"
android:layout_height="100sp"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/buttonClear"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@drawable/custombuttonred"
android:text="@string/clear"
android:layout_weight=".40"
android:textSize="50sp" />
<ImageButton
style="@style/ButtonText"
android:id="@+id/c101_image"
android:layout_width="40sp"
android:layout_height="100sp"
android:scaleType="centerInside"
android:background="@drawable/cloud101"
android:layout_weight=".20" />
<Button
android:id="@+id/buttonBackspace"
style="@style/ButtonText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@drawable/custombuttonred"
android:text="@string/backspace"
android:layout_weight=".40"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutH2"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button1"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="@string/b1"
android:textSize="110sp" />
<Button
android:id="@+id/button2"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="2"
android:textSize="110sp" />
<Button
android:id="@+id/button3"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="3"
android:textSize="110sp" />
<Button
android:id="@+id/buttonDevide"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="/"
android:textSize="110sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutH3"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button4"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="4"
android:textSize="110sp" />
<Button
android:id="@+id/button5"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="5"
android:textSize="110sp" />
<Button
android:id="@+id/button6"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="6"
android:textSize="110sp" />
<Button
android:id="@+id/buttonMult"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="X"
android:textSize="110sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutH4"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button7"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="7"
android:textSize="110sp" />
<Button
android:id="@+id/button8"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="8"
android:textSize="110sp" />
<Button
android:id="@+id/button9"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="9"
android:textSize="110sp" />
<Button
android:id="@+id/buttonMinus"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="-"
android:textSize="110sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutH5"
android:layout_width="fill_parent"
android:layout_height="50sp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button0"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombutton"
android:text="0"
android:textSize="110sp" />
<Button
android:id="@+id/buttonDot"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="."
android:textSize="110sp" />
<Button
android:id="@+id/buttonEq"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttongreen"
android:text="="
android:textSize="110sp" />
<Button
android:id="@+id/buttonPlus"
style="@style/ButtonText"
android:layout_width="50sp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/custombuttonblue"
android:text="+"
android:textSize="110sp" />
</LinearLayout>
</LinearLayout>
我读过有关不同屏幕大小的问题,但不管我使用sp或dp,它在800x480屏幕上看起来仍然很糟糕。我应该怎么做才能正确显示字体并且图片能够很好地居中并且不会太紧?
如果两台设备具有相同的密度,我可以看到发生这种情况,并且它恰好适用于较大的设备。你可以拿出边距并把文本居中?不幸的是,大小修饰符在android3.2之前是不可用的,或者他们可能有帮助。 – Shellum 2012-03-09 19:22:46
只是试试这个:我认为它解决您的问题:[链接] http://developer.android.com/guide/practices/screens_support.html – 2012-03-09 19:30:00