2011-12-03 87 views
1

即时使用该代码;相对布局不放按钮

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:text="Button" /> 

</RelativeLayout> 

由于某种原因,这不适用于模拟器与540x960。该按钮出现在模拟器的中间。

在我的droid2中,它能正常工作。

enter image description here

左图展示它是如何工作在我的Droid 2的手机,而右侧显示如何是工作在HTC sensationXe模拟器

+0

什么操作系统版本是模拟器?也许你应该把TextView固定在某个东西上。 –

+1

我已经更新了我的问题,并且我上传了一些图片,以便您能够看到问题 – Yayo28

回答

0

你必须设置锚点您的TextView ..尝试对齐按钮左侧或右侧的文本视图,问题应该消失。

0

方向属性不适用于相对布局。请尝试以下步骤

<TextView 
    android:id="@+id/helloid" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_below="@id/helloid" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:text="Button" /> 
+0

这不起作用,我已经上传了一些关于此问题的图片。 – Yayo28

1

我已经找到问题的答案。我是编译我的应用程序作为anddroid 1.5,现在我已将此添加到清单

<uses-sdk android:minSdkVersion="3" 
    android:targetSdkVersion="4" /> 

和我编译到Android 1.6

现在是它必须是

0

编辑XML的地方通过这个,它会工作。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:gravity="bottom" 
     android:text="Button" /> 

</RelativeLayout>