2012-03-09 73 views
0

我有我的Android應用程序的問題。當我使用我的惠普觸摸板,其分辨率爲1024x768,一切看起來都不錯。然而,當我測試了一個800×480(Desire HD的)這個事情發生了: enter image description here不同的屏幕分辨率顯示在平板電腦(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屏幕上看起來仍然很糟糕。我應該怎麼做才能正確顯示字體並且圖片能夠很好地居中並且不會太緊?

+0

如果兩臺設備具有相同的密度,我可以看到發生這種情況,並且它恰好適用於較大的設備。你可以拿出邊距並把文本居中?不幸的是,大小修飾符在android3.2之前是不可用的,或者他們可能有幫助。 – Shellum 2012-03-09 19:22:46

+0

只是試試這個:我認爲它解決您的問題:[鏈接] http://developer.android.com/guide/practices/screens_support.html – 2012-03-09 19:30:00

回答

2

第一:你不應該用戶sp的觀點尺寸。對於視圖的尺寸,用戶dp,對於文本大小,用戶sp。 第二:如果你使用weightsumlayout_weight,對意見寬度你不需要尺寸,你給他們0dp價值,他們將繪製好的。

例如,如果您使用此配置:

<ImageButton 
     style="@style/ButtonText" 
     android:id="@+id/c101_image" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:scaleType="centerInside" 
     android:background="@drawable/cloud101" 
     android:layout_weight=".20" /> 

您的ImageButton應該正確地在所有屏幕上顯示。 對所有視圖使用相同的技巧,它應該可以解決您的問題。

注意:用較小的字體爲您的文本:)

祝你好運, Arkde

+0

我只是現在需要找出一種方法,使平板電腦上的字體更大屏幕上,在平板電腦屏幕70 SP再次太小了:( – 2012-03-09 19:31:57

1

你TEXTSIZE是該設備太大。

讓自己的佈局,正常的文件夾中的資源目錄中,並在那裏貼上佈局的副本。將按鈕上的110sp更改爲更小的按鈕。也許開始嘗試像70sp或其他東西。測試不同的尺寸,直到看起來不錯。

此外,如果您打算讓您的應用程序支持,你需要讓你的佈局文件的另一個副本爲他們太小的屏幕。

相關問題