2012-03-28 52 views
1

對於大多數.xml文件,我的設計中存在一些缺陷,其中一些屏幕上的尺寸通常較大,而較低的屏幕上的尺寸通常較大。我使用px(像素)。Android .xml設計

我知道這對我來說可能是一個糟糕的選擇,因爲新手機會以更高的像素比例結束。例如三星Galaxy Nexus將所有文本製作成小文本。

什麼會是一個更合適的類型用於未來的電話來?

附加:

我已經使用了很長一段時間的線性佈局,但現在,我需要一個滾動的長菜單我設計嵌套在滾動型,其滾動型嵌套的線性佈局的RelativeLayout的。嵌套tableLayout以更好地控制視圖會更好嗎?

不想氾濫的問題屏幕因爲它看起來醜陋。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

      <TextView 
       android:id="@+id/tab_tv_one" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/auto_Action" 
       android:background="#666666" 
       android:text="@string/options_dialog_menu_Action" 
       android:textSize="27px" 
       /> 

      <RadioGroup 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 

      <RadioButton 
       android:id="@+id/FirstOption" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/manual_Action" 
       android:layout_below="@+id/tab_tv_one" 
       android:text="@string/options_dialog_menu_Auto_Action" 

       android:textSize="27px" /> 

      <RadioButton 
       android:id="@+id/SecondOption" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/tab_tv_two" 
       android:layout_below="@+id/auto_Action" 
       android:text="@string/options_dialog_menu_Manual_Action" 
       android:textSize="27px" 
       android:onClick="onClick" 
       android:clickable="true" 

       /> 

      <RadioButton 
       android:id="@+id/ThirdOption" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/tab_tv_two" 
       android:layout_below="@+id/manual_Action" 
       android:textSize="27px" 
       android:onClick="onClick" 
       android:clickable="true" 

       /> 

      </RadioGroup> 



      <TextView 
       android:id="@+id/tab_tv_two" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/text_size" 
       android:layout_below="@+id/manual_Action" 
       android:background="#666666" 
       android:text="@string/options_dialog_menu_Layout_Options" 
       android:textSize="27px" 
       /> 

      <TextView 
       android:id="@+id/text_size" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/background_clr" 
       android:layout_below="@+id/tab_tv_two" 
       android:text="@string/options_dialog_menu_Text_Size" 
       android:textSize="27px" 
       android:onClick="onClick" 
       android:clickable="true" 

       /> 

      <TextView 
       android:id="@+id/Options_clr" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/brightness_ctrl" 
       android:layout_below="@+id/text_size" 
       android:text="@string/options_dialog_menu_Color_Options" 
       android:textSize="27px" 
       android:onClick="onClick" 
       android:clickable="true" 

       /> 

      <TextView 
       android:id="@+id/brightness_ctrl" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/background_clr" 
       android:text="@string/options_dialog_menu_Brightness_color" 
       android:textSize="27px" 
       android:onClick="onClick" 
       android:clickable="true" 

       /> 
      <TextView 
       android:id="@+id/backToBasics" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/brightness_ctrl" 
       android:text="@string/options_dialog_menu_Back_To_Basics" 
       android:textSize="27px" 

       android:onClick="onClick" 
       android:clickable="true" 
       /> 


    </LinearLayout> 
    </ScrollView> 
</RelativeLayout> 
+1

我認爲你需要使用dp而不是像素。 – kosa 2012-03-28 20:26:43

回答

1

不要使用像素,請使用dp(又名dip又稱密度獨立像素)。否則,如你所述,尺寸將取決於密度,這是不好的。

它不僅僅是星系之間的聯繫,ldpi電話看起來不同於mdpi,它看起來不同於hdpi等。很少有任何理由使用px尺寸,特別是關於視圖尺寸。

關於你的額外問題,它完全取決於你想要你的佈局看起來像什麼。沒有看到代碼和/或至少知道你想要發生什麼(相比你現在看到的),沒有人真的能夠回答這個問題。

+0

我將添加代碼。不想太多地淹沒問題屏幕。 – sdfwer 2012-03-28 20:30:14

+0

因此,除了將像素更改爲dp(這將是一種痛苦,但完全值得),您不會做任何不合理的事情。除非讓佈局看起來像你想要的那樣,否則就按原樣放置。如果你發現你需要在桌面佈局中使用功能,沒有任何理由不使用它,我可以看到,並且當你真正需要它時,你可以隨時切換。 – 2012-03-28 20:56:54