0

我正在开发一个应该支持多个屏幕的应用程序。对于普通屏幕,我将布局设置在 viewflipper 中,这样我的图标就不会拥挤。但是我想在大屏幕上做的是将所有图标放在一个布局中,而不使用 viewflipper 来利用屏幕。

这是我的普通屏幕布局:

<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。

4

1 回答 1

2

Preferably you would use the regular xml files and place them in the right folders (e.g. layout-xlarge) then you have a layout for smaller sizes and layouts for larger sizes.

Also programatically depending on which version of android you are outputting to you would use

getResources().getConfiguration()

and using that find if the device screen size is

SCREENLAYOUT_SIZE_XLARGE

for xlarge screens (> 7inches) or

SCREENLAYOUT_SIZE_LARGE

for large screens (between 4 inches and 7 inches) the first boundry is not defined before HoneyComb (API 11+) while the second boundry has problems on certain devices.

EDIT: I agree with FoamyGuy fragments would be so much better, especially since you can control each fragments logic specifically (eg. create a layout for large screens and create a layout for fragment with small screens (if you want to use a view flipper) or just start a new fragment like a new activity as shown in the Fragment docs).

于 2013-03-06T22:23:44.680 回答