无法使用RelativeLayout完全填满屏幕,并且无法在键盘打开时调整大小

时间:2013-02-11 01:58:43

标签: android xml relativelayout

所以这是我的XML。我试图填满整个屏幕,当我在Eclipse中查看它时,它会填满整个屏幕。但是,当我在手机上打开它时,一切都变小了,并且有视图覆盖。我不知道发生了什么。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:id="@+id/front"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:text="Front"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/frontInput"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_below="@+id/front"
    android:ems="10" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/frontInput"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:text="Back"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/backInput"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/back"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:ems="10"
    android:inputType="textMultiLine" />

<TextView
    android:id="@+id/background"
    android:layout_width="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/backInput"
    android:layout_marginTop="44dp"
    android:text="Background"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Spinner
    android:id="@+id/colors_spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/backInput"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="22dp"
    android:layout_toRightOf="@+id/background" 
    />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/colors_spinner" >

    <Button
    android:id="@+id/save"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Save" />

    <Button
    android:id="@+id/cancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="Cancel" />

</LinearLayout>

</RelativeLayout>

这就是它在Eclipse中的样子。 XML IN Eclipse

但我得到了这个:XML viewd on my phone

另一件事是,当我打开键盘时,我的视图没有重新调整,所以你可以看到一切,但是更小,这样你就可以看到你正在输入的内容等...我已经为特定活动添加了android:windowSoftInputMode="adjustResize"但是什么都没发生......有什么想法吗?谢谢你们......

1 个答案:

答案 0 :(得分:1)

如果您使用adjustResize,它会调整所有内容以尽可能地适应它。另一个选项是adjustPan,它将滚动窗口,以便聚焦的EditText将位于视图中,并且插入符号可见。除此之外,没有真正的方法来控制事物。

在你的情况下,你有一些确切的高度,所以它不适用于调整大小,因为你不能缩小精确的高度。

此外,永远不要相信Eclipse中的外观。它试图解决与Android真正做事情无关的任何代码,它应被视为一种估计。实际布局可能看起来有很大不同,特别是对于复杂的布局。

相关问题