2012-11-15 82 views
0

所以我是Android開發的新手,對佈局有疑問。當我在Eclipse中創建我的應用程序時,我已經設置了它,以便我可以看到它在Nexus S上的外觀(4英寸,480 x 800)。在我的Exhibit 2 4G(3.7英寸,480 x 800)上打開它時,這看起來不錯,但是當我在Nexus 7上打開時它看起來很糟糕。按鈕位於錯誤的地方,而且看起來並不像相同。我認爲這與佈局有關?當我在java中創建Windows應用程序時,我使用佈局,如邊框佈局,網格佈局,流佈局,蝕刻......然後將其添加到框架中。這樣,無論我調整窗口的大小,它總是看起來一樣。你如何在Android中做到這一點?此外,還有一些話題,但是當在文本框中顯示數字時,你如何使它只顯示到百分之一的位置?我開始創建處理提示,銷售價格和蝕刻的應用程序,並且不需要將最終計算的價格保留在小數點後第5位。初學者Android佈局

這裏是我的佈局代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Main" > 

    <TextView 
     android:id="@+id/tagpricetext" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="18dp" 
     android:layout_marginTop="21dp" 
     android:text="Enter tag price:" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     tools:ignore="HardcodedText" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tagpricetext" 
     android:layout_marginTop="36dp" 
     android:layout_toLeftOf="@+id/tagprice" 
     android:text="Enter % off:" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     tools:ignore="HardcodedText" /> 

    <Button 
     android:id="@+id/calc" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tagpricetext" 
     android:layout_alignRight="@+id/percentoff" 
     android:layout_below="@+id/textView1" 
     android:layout_marginTop="31dp" 
     android:text="Calculate" 
     tools:ignore="HardcodedText" /> 

    <TextView 
     android:id="@+id/saleprice" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/textView2" 
     android:layout_alignBottom="@+id/textView2" 
     android:layout_toRightOf="@+id/textView1" 
     android:text="  " 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     tools:ignore="HardcodedText" /> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tagpricetext" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical" 
     tools:ignore="UselessLeaf" > 

    </LinearLayout> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/calc" 
     android:layout_below="@+id/calc" 
     android:layout_marginTop="20dp" 
     android:text="Sale Price: $" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     tools:ignore="HardcodedText" /> 

    <EditText 
     android:id="@+id/tagprice" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/tagpricetext" 
     android:layout_marginLeft="18dp" 
     android:layout_toRightOf="@+id/tagpricetext" 
     android:ems="10" 
     android:inputType="numberDecimal" > 

     <requestFocus /> 
    </EditText> 

    <EditText 
     android:id="@+id/percentoff" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/tagprice" 
     android:layout_alignTop="@+id/textView1" 
     android:ems="10" 
     android:inputType="numberDecimal" /> 

</RelativeLayout> 

這裏是截圖: https://www.dropbox.com/sh/cq327dyhzzb1af6/PjRXqS2DWc/screenshot.jpg

提前感謝!

布蘭登

三星圖表2 4G(T-Mobile)的

+1

您需要顯示您使用的與佈局相關的代碼,並且屏幕截圖不會受到傷害。這是關於設置正確的寬度/高度,並使用適合您的特定任務的正確佈局。 (例如,垂直列出項目,使用'RelativeLayout'處理很差,儘管有任何誘惑。) – Eric

+0

ok我添加了佈局代碼和截圖鏈接。我現在使用默認的RelativeLayout。 – Brandon

+0

以下是我在Nexus S上製作的應用程序: https://www.dropbox.com/s/4kuat46iqacd7kg/tc%20small.png 以下是Nexus 7上的外觀: https://www.dropbox.com/s/i2gbi7h1gifxy9q/tc%20nexus7.png Nexus 7上的文本結果應該更接近像Nexus S上的其他元素。 – Brandon

回答

0

這篇文章的開發者指南中涵蓋了你需要知道的關於支持不同屏幕尺寸的一切: http://developer.android.com/guide/practices/screens_support.html

如果你尋找中心的一切,然後只是用center_horizo​​ntal標記這一切...

至於你的號碼,也許乘以100,Math.round它,然後除以100?