2013-01-21 76 views
2

我一直在測試大多數我的佈局在Galaxy 5 Media Player上,並且佈局都在尋找我如何在常規layout文件夾中設計它們。我使用SDK 10,所以我不使用layout-sw600dp類型的文件夾,而不是我用/layout/layout-large我在大屏幕設備上的佈局與大屏幕預覽不匹配

雖然我的佈局看起來罰款銀河5的球員,當我嘗試過其他的設備上,這將是使用,Lenovo Ideapad A1,觀點是不正確的。我在/layout-large中爲7「平板電腦創建了一個新的xml文件,但現在預覽中的內容與我的設備上的內容不匹配

我使用RelativeLayout,但沒有任何內容但有8個按鈕第一個按鈕宣告與底部對齊,則每個以下按鈕被放置在它下面的一個以上,具有marginBottom參數集

這是爲原始視圖xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/v2" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/exitButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="36dp" 
     android:layout_alignParentBottom="true" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_exit" /> 

    <Button 
     android:id="@+id/findDeviceButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/exitButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_find_device" /> 

    <Button 
     android:id="@+id/cebusButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/findDeviceButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_cebus" /> 

    <Button 
     android:id="@+id/operationsButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/cebusButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_operations" /> 

    <Button 
     android:id="@+id/monitorButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/operationsButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_monitor" /> 

    <Button 
     android:id="@+id/wavesButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/monitorButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_waves" /> 

    <Button 
     android:id="@+id/statusButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/wavesButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_status" /> 

    <Button 
     android:id="@+id/more_parametersButton" 
     android:layout_width="350dp" 
     android:layout_height="60dp" 
     android:layout_marginBottom="18dp" 
     android:layout_above="@id/statusButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_parameters" /> 

</RelativeLayout> 

當運行此在我的7英寸設備上,這些按鈕很大,並且越過了屏幕的頂部。但是在Eclipse的預覽中,這些按鈕都很適合屏幕。爲什麼預覽會讓我看到與我所期望的不同的視角?

編輯:

我已經調整了XML文件,使之在我的平板電腦工作。儘管現在預覽看起來更糟,但下面的XML文件會生成我想要的設備上的結果。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/v2" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/exitButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="30dp" 
     android:layout_alignParentBottom="true" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_exit" /> 

    <Button 
     android:id="@+id/findDeviceButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/exitButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_find_device" /> 

    <Button 
     android:id="@+id/cebusButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/findDeviceButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_cebus" /> 

    <Button 
     android:id="@+id/operationsButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/cebusButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_operations" /> 

    <Button 
     android:id="@+id/monitorButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/operationsButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_monitor" /> 

    <Button 
     android:id="@+id/wavesButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/monitorButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_waves" /> 

    <Button 
     android:id="@+id/statusButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/wavesButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_status" /> 

    <Button 
     android:id="@+id/more_parametersButton" 
     android:layout_width="300dp" 
     android:layout_height="50dp" 
     android:layout_marginBottom="15dp" 
     android:layout_above="@id/statusButton" 
     android:textColor="@android:color/white" 
     android:background="@drawable/sel_button_round" 
     android:text="@string/main_parameters" /> 

</RelativeLayout> 

回答

4

我認爲它不是你的佈局問題,檢查屏幕兼容性

如果你的應用是僅小和正常屏幕兼容,無論屏幕像素密度,那麼你必須指定八個不同的元素,因爲每個屏幕尺寸有四個不同的密度配置

<compatible-screens> 
<screen android:screenSize=["small" | "normal" | "large" | "xlarge"] 
     android:screenDensity=["ldpi" | "mdpi" | "hdpi" | "xhdpi"] /> 
... 

有關詳細信息檢查此LINK

這裏是你如何能確保快速的檢查列表,您的應用程序正確地顯示在不同的屏幕上:

使用WRAP_CONTENT,FILL_PARENT,或在一個XML配置文件中指定的尺寸時,dp單位

  1. 不要在應用代碼中使用硬編碼的像素值

  2. 不要使用AbsoluteLayout(它不建議使用)

  3. 針對不同屏幕密度

供應替代位圖資源Android系統幫助應用實現密度獨立兩種方式:

  1. 系統調整dp單位適合當前屏幕 密度

  2. 系統根據當前屏幕密度基於 將可繪製資源縮放到適當的大小Y,如果有必要

欲瞭解更多信息,請檢查該LINK

相關問題