模拟器上显示的布局,但没有完全显示在手机上

问题描述:

我有一个嵌套的线性布局。在我的模拟器上,完整的布局是可见的。但在我的手机上,布局并未完全显示。它会在两者之间切断。它不显示最底部的元素。模拟器上显示的布局,但没有完全显示在手机上

如何使布局完全适合我的屏幕?

截图怎么看我的手机上:

screenshot of how it looks on my phone:

这里是我的代码:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@raw/bg1"  
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_marginTop="20dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"   
     android:orientation="horizontal"> 

     <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="60dp" 
     android:layout_height="60dp"  
     android:src="@drawable/logo" /> 

     <TextView 
     android:id="@+id/textView1" 
     android:layout_marginLeft="10dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center"  
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" />  

    </LinearLayout> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="30dp" 
     android:layout_centerHorizontal="true"   
     android:text="Button" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="30dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:orientation="horizontal"> 

     <EditText 
     android:id="@+id/editText1" 
     android:background="#33FFFFFF" 
     android:layout_width="200dp" 
     android:layout_height="200dp" /> 

     <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="65dp"  
     android:src="@drawable/ic_talk" /> 

    </LinearLayout> 

    <Button 
     android:id="@+id/button2" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_gravity="center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

</LinearLayout> 
+0

我认为这是不明确的,你说的话,你应该提供一些截图。 – 2013-03-26 10:52:51

+1

您的模拟器宽度和高度是否与您的手机相同? – Riskhan 2013-03-26 10:58:55

+0

@OvidiuLatcu我已经更新了这个问题。请检查。 – newbee 2013-03-26 10:59:34

如果您使用权重,无论屏幕大小如何,您都会得到相同的结果。我认为在这种情况下你的问题。 这是此页解释: http://developer.android.com/training/basics/firstapp/building-ui.html

例如:

<EditText android:id="@+id/edit_message" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:hint="@string/edit_message" /> 

这是怎么一回事,因为你在声明宽度,高度和元素的寄宿生一个静态数字。您的设备和仿真器必须具有不同的大小,并且您有硬编码的值,可以使其在仿真器上正确显示,但不会显示在任何其他设备上。阅读this了解如何正确地进行布局。

+0

根据你给出的链接,它说'通常,不建议使用绝对单位(如像素)指定布局宽度和高度。相反,使用诸如密度独立像素单位(dp),wrap_content或fill_parent之类的相对测量是更好的方法,因为它有助于确保您的应用程序能够在各种设备屏幕尺寸上正确显示。接受的测量类型在可用资源文档中定义。因为我已经在所有硬编码值中使用** dp **,它应该可以工作,不是吗?我错过了你的代码中的 – newbee 2013-03-26 11:10:23

+0

道歉。视图的底部是从屏幕上丢失的吗?如果是这样,您将需要使用滚动视图,以便您可以将其余项目滚动到页面上。 – chefburns 2013-03-26 11:17:53