坏的xml或android兼容性问题?

坏的xml或android兼容性问题?,android,xml,layout,Android,Xml,Layout,我正在android上开发我的第一个应用程序,我认为我的应用程序符合支持多个屏幕所需的要求(仅使用dp或sp等) 然而,我似乎做错了什么。文本视图在屏幕底部重叠 现在…我是否编写了糟糕的xml,还是需要为每个android版本添加不同的布局,以确保避免此类问题 第一个设备规格(docomo箭头NX F-06E)1080×1920像素,16777216色 第一个设备屏幕截图: 第二款设备规格(LG L-07C Optimus)480 x 800像素,256K颜色 第二个设备屏幕截图: 下面是x

我正在android上开发我的第一个应用程序,我认为我的应用程序符合支持多个屏幕所需的要求(仅使用dp或sp等)

然而,我似乎做错了什么。文本视图在屏幕底部重叠

现在…我是否编写了糟糕的xml,还是需要为每个android版本添加不同的布局,以确保避免此类问题

第一个设备规格(docomo箭头NX F-06E)1080×1920像素,16777216色 第一个设备屏幕截图:

第二款设备规格(LG L-07C Optimus)480 x 800像素,256K颜色 第二个设备屏幕截图:

下面是xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/dark_green"
android:orientation="vertical"
 >

<ImageView
 android:id="@+id/image"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_marginTop="5dp"
 android:src="@drawable/sakai" />

<TextView
android:id="@+id/random_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="false"
android:layout_alignTop="@id/image"
android:layout_toLeftOf="@+id/chronometer"
android:layout_toRightOf="@id/image"
android:background="@drawable/bubble_bl"
android:text="@string/index"
android:textSize="20.5sp" />

<Chronometer android:id="@+id/chronometer"
 android:format="@string/chronometer_initial_format"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentRight="true"
 android:layout_marginRight="0dip"
 android:layout_weight="0.5"
 android:paddingBottom="30dip"
 android:paddingTop="30dip"
 />
 <Button
 android:layout_below="@id/image"
 android:id="@+id/askquestion"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/ask"
 style="@style/ButtonText" 
 android:background="@drawable/btn_blue_states" 
 />
 <Button
  android:layout_below="@id/askquestion"
  android:id="@+id/answer1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/ask" 
  style="@style/ButtonText" 
  android:background="@drawable/btn_blue_states"/>
  <Button
  android:layout_below="@id/answer1"
  android:id="@+id/answer2"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/ask" 
  style="@style/ButtonText" 
  android:background="@drawable/btn_blue_states"/>
  <Button
  android:id="@+id/answer3"
  android:layout_below="@id/answer2"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/ask"
  style="@style/ButtonText" 
  android:background="@drawable/btn_blue_states" />
  <Button
  android:id="@+id/answer4"
  android:layout_below="@id/answer3"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/ask" 
  style="@style/ButtonText" 
  android:background="@drawable/btn_blue_states"/>
  <TextView
  android:id="@+id/score_field"
  android:layout_below="@id/answer4"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_marginBottom="5dip"
  android:gravity="center"
  android:text="@string/score"
  android:textSize="24.5sp" 
  /> 
  <TextView
  android:id="@+id/performance_field"
  android:layout_below="@id/score_field"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:textSize="24.5sp" 
  />

  <LinearLayout android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" android:layout_alignParentBottom="true"
  android:weightSum="4.0" >
<TextView
  android:id="@+id/difficult_textview"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:text="@string/difficulty"
  android:textSize="24.5sp" 
  />
  <LinearLayout android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/linearLayoutWithButtons"
  android:orientation="horizontal" 
  android:weightSum="4.0" >

  <Button
  android:id="@+id/diff1"
  style="@style/ButtonText"
  android:layout_weight="1.0"
  android:layout_height="wrap_content"
  android:background="@drawable/btn_blue_states"
  android:text="@string/one" />
      <Button
      android:id="@+id/diff2"
      style="@style/ButtonText"
      android:layout_weight="1.0"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/btn_blue_states"
      android:text="@string/two" />
      <Button
      android:id="@+id/diff3"
      style="@style/ButtonText"
      android:layout_weight="1.0"
      android:layout_height="wrap_content"
      android:background="@drawable/btn_blue_states"
      android:text="@string/three" />
      <Button
      android:id="@+id/diff4"
      style="@style/ButtonText"
      android:layout_weight="1.0"
      android:layout_height="wrap_content"
      android:background="@drawable/btn_blue_states"
      android:text="@string/four" />

  </LinearLayout>

  </LinearLayout>


这是一个简单的纵横比问题:

  • 1080x1920是16:9
  • 480x800是5:3
因此,分辨率越高的屏幕是一个更长(更高)的矩形。您的布局设计得很好,一部分布局挂到底部,另一部分挂在顶部,但您在设计布局时考虑了较高的屏幕,因此在较小的屏幕上,所有内容都在一起运行。您有两种选择之一:

  • 重新设计布局以适合较短的屏幕,在这种情况下,在较高的屏幕上,它只会拉伸以显示顶部和底部之间更多的额外空间
  • 使用资源限定符根据屏幕高度创建两种不同的布局。只有当您尝试实现更完美的像素外观时,无论设备的屏幕外观如何,这种努力水平才有意义

  • 如果您将屏幕截图附加在屏幕上以减小文本大小,或者根据屏幕尺寸进行多个XML布局配置,那么您会更容易获得帮助。请提供有关您正在使用的绘图表的信息?你在使用9patch图片吗?你的意思是在评论中吗?它应该如何出现它应该如何出现ishttp://i.stack.imgur.com/rhtrS.jpgYou 没有告诉我们屏幕的实际尺寸。我猜第二个明显更小,所以空间不够——这是一个跨设备GUI工具包还无法解决的问题。我将尝试重新确定字体的尺寸!然后我将查找资源限定符,以确保这些事情不会再次发生!非常感谢你。