Java 正常大小屏幕的Android布局问题

Java 正常大小屏幕的Android布局问题,java,android,android-layout,Java,Android,Android Layout,我目前正在测试一个最近完成的Android应用程序,在不同屏幕的布局上我有点挣扎。基本上,我只是无法为每个布局找出一个适合所有人的尺寸 正常的布局特别糟糕。在Eclipse编辑器上我看到一件事,在模拟器上我看到另一件事,在某些设备上我看到另一件事。我真的不知道如何特别修复这些屏幕,因为它们在编辑器上似乎没有错。以下是我得到的一些例子: 编辑器的外观: 请注意,模拟器的外观与编辑器上的手机相同: 摩托罗拉D3设备的屏幕外观语言不同,但布局相同!: 我不知道这是否相关,但以下是我针对特定屏幕的xml

我目前正在测试一个最近完成的Android应用程序,在不同屏幕的布局上我有点挣扎。基本上,我只是无法为每个布局找出一个适合所有人的尺寸

正常的布局特别糟糕。在Eclipse编辑器上我看到一件事,在模拟器上我看到另一件事,在某些设备上我看到另一件事。我真的不知道如何特别修复这些屏幕,因为它们在编辑器上似乎没有错。以下是我得到的一些例子:

编辑器的外观:

请注意,模拟器的外观与编辑器上的手机相同:

摩托罗拉D3设备的屏幕外观语言不同,但布局相同!:

我不知道这是否相关,但以下是我针对特定屏幕的xml代码:

  <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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".EnterActivityActivity" >

<TextView
    android:id="@+id/recommendationTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="29dp"
    android:text="@string/recommendation_enter"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/timeTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/recommendationTextView"
    android:layout_marginTop="48dp"
    android:layout_toLeftOf="@+id/recommendationTextView"
    android:text="@string/time_recommendation_enter" />

<EditText
    android:id="@+id/changeRecommendationEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/changeRecommendationtextView"
    android:layout_alignBottom="@+id/changeRecommendationtextView"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/activityEnterButton"
    android:ems="5"
    android:inputType="number"
    android:maxLength="5"
    android:focusable="false"/>

<Button
    android:id="@+id/activityEnterButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/pedometerButton"
    android:layout_centerHorizontal="true"
    android:text="@string/enter_button_recommendation_enter" />

<Button
    android:id="@+id/pedometerButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="@string/open_pedometer_button_recommendation_enter" />

<TextView
    android:id="@+id/changeRecommendationtextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/changeRecommendationButton"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="28dp"
    android:text="@string/change_recommendation_enter" />

<Button
    android:id="@+id/changeRecommendationButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/activityEnterButton"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"
    android:text="@string/change_button_recommendation_enter" />

<EditText
    android:id="@+id/timeEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/recommendationTextView"
    android:layout_alignTop="@+id/timeTextView"
    android:ems="3"
    android:focusable="false"
    android:inputType="number" 
    android:maxLength="3"/>

<TextView
    android:id="@+id/distanceTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/timeTextView"
    android:layout_marginTop="18dp"
    android:layout_toLeftOf="@+id/changeRecommendationButton"
    android:text="@string/distance_recommendation_enter" />

<EditText
    android:id="@+id/distanceEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/changeRecommendationButton"
    android:layout_below="@+id/timeTextView"
    android:ems="5"
    android:focusable="false"
    android:inputType="number" 
    android:maxLength="5"/>

 </RelativeLayout>

我怎样才能准确地解决这个问题,使它看起来很好,并且与各种屏幕和设备一致?

您的模拟器运行的是android 2.3,并且没有使用与设备和编辑器相同的主题。问题是,您使用了大量硬编码值,用于那些原本在屏幕上运行良好的边距屏幕例如,如果您从一开始就在较小的屏幕上开发,那么布局对于较大的屏幕可能是不好的。尝试使用垂直线性布局,并使用这些重力属性。在修复任何内容之前,请确保您已经阅读了此页面:。7月,您必须遵循android guidlines为所有屏幕绘制布局,我认为您在其中使用了大量静态值,这就是问题所在。