2013-03-06 195 views
0

我正在開發一個應該支持多個屏幕的應用程序。對於正常的屏幕,我已將視圖設置在視圖縮放器中,因此我的圖標不會擁擠。但是我想在大屏幕上進行的操作是將所有圖標放在一個佈局中,而不使用viewflipper來利用屏幕。Android確定屏幕尺寸

這裏是我的正常屏幕布局:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/lighterred" 
android:layout_gravity="center" 
android:orientation="vertical" > 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/logo" 
    android:layout_gravity="center" 
    android:text="@string/app_name" 
    android:textSize="30sp" 
    android:padding="15dp" 
    android:textStyle="bold" 
    android:textColor="@color/white" 
    android:contentDescription="@string/app_name" /> 

<ViewFlipper 
android:id="@+id/mainFlipper" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
android:background="@color/white" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:gravity="center_vertical|center" 
android:orientation="vertical" > 


<TextView 
    android:id="@+id/tvMainNote" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textStyle="bold" 
    android:text="@string/slidetoleft" /> 

<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 


<Button 
    android:id="@+id/ibSymptoms" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/symptoms" 
    android:textStyle="bold" 
    android:textColor="@color/black" 
    android:layout_margin="20dp" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/symptoms" /> 

<Button 
    android:id="@+id/ibConditions" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/conditions" 
    android:textStyle="bold" 
    android:layout_margin="20dp" 
    android:textColor="@color/black" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/conditions" /> 

<Button 
    android:id="@+id/ibMedicalAssessment" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/medicalassessment" 
    android:textStyle="bold" 
    android:textColor="@color/black" 
    android:layout_margin="20dp" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/med_assessments" /> 

<Button 
    android:id="@+id/ibProfile" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/profile" 
    android:textStyle="bold" 
    android:layout_margin="20dp" 
    android:textColor="@color/black" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/profile" /> 

</LinearLayout> <!-- 2nd row --> 


</LinearLayout> 


<LinearLayout 
android:background="@color/white" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:gravity="center_vertical|center" > 


<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

<Button 
    android:id="@+id/ibTests" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/tests" 
    android:textStyle="bold" 
    android:layout_margin="20dp" 
    android:textColor="@color/black" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/tests" /> 

<Button 
    android:id="@+id/ibTreatment" 
    android:layout_margin="20dp" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/treatment" 
    android:textStyle="bold" 
    android:textColor="@color/black" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/treatment" /> 


</LinearLayout> 


<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

<Button 
    android:id="@+id/ibSpecialists" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/specialists" 
    android:textStyle="bold" 
    android:layout_margin="20dp" 
    android:textColor="@color/black" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/specialists" /> 

<Button 
    android:id="@+id/ibDisclaimer" 
    android:layout_margin="20dp" 
    android:layout_width="110dp" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:contentDescription="@string/app_name" 
    android:text="@string/about" 
    android:textStyle="bold" 
    android:textColor="@color/black" 
    android:background="@drawable/custom_button" 
    android:drawableTop="@drawable/disclaimer" /> 

</LinearLayout> 


</LinearLayout> 

</ViewFlipper> 
</LinearLayout> 

所以,我怎麼能做到這一點在大屏幕?

感謝和regrads。

+1

現在是時候讓你[學習碎片的喜悅](https://developer.android.com/guide/components/fragments.html) – FoamyGuy 2013-03-06 22:26:06

+0

@FoamyGuy它與2.3兼容嗎? – 2013-03-07 11:53:47

+0

如果您使用應該與您的sdk一起出現的兼容性庫(或通過sdk管理器下載它) – Raigex 2013-03-07 17:09:50

回答

2

最好你可以使用普通的xml文件並將它們放在正確的文件夾中(例如layout-xlarge),然後你就可以獲得更小尺寸的佈局和更大尺寸的佈局。

而且編程,這取決於你是輸出到你的Android的版本將使用

getResources().getConfiguration() 

,並使用該發現如果該設備的屏幕尺寸爲

SCREENLAYOUT_SIZE_XLARGE 

爲XLARGE屏幕(>7英寸) 或

SCREENLAYOUT_SIZE_LARGE 

大屏幕(下注ween 4英寸和7英寸) 第一個邊界在HoneyComb(API 11+) 之前未定義,而第二個邊界在某些設備上有問題。

編輯: 我FoamyGuy片段同意就好多了,特別是因爲你可以明確控制每個片段邏輯(例如創建大屏幕的佈局,併爲小屏幕片段佈局(如果你想。使用視圖鰭狀肢),或者像片段文檔中所示的那樣,像新活動一樣開始新的片段)。

+0

是的,我把它放在layout-xlarge文件夾中。但是我只有一個用於普通和大屏幕的java類。 – 2013-03-07 11:55:49

+0

你是否動態填充它們?或者您是否已經在預先準備的佈局中使用了所有想要使用的按鈕? – Raigex 2013-03-07 17:07:45