【问题标题】:Cannot completely fill the screen with RelativeLayout and cannot resize on Keyboard opening无法使用 RelativeLayout 完全填满屏幕,并且无法在键盘打开时调整大小
【发布时间】:2013-02-11 01:58:42
【问题描述】:

这是我的 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 中的样子。

但我明白了:

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

【问题讨论】:

    标签: android xml android-relativelayout


    【解决方案1】:

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

    在您的情况下,您那里有一些确切的高度,因此它不适用于调整大小,因为您无法缩小确切的高度。

    另外,永远不要相信事物在 Eclipse 中的样子。它试图将与 Android 真正做事的方式没有任何代码共享的东西列出来,它应该被视为一种估计。真实的布局最终可能会看起来大不相同,尤其是对于复杂的布局。

    【讨论】:

    • 那么我应该怎么做才能让它工作呢?这就是我感兴趣的......我希望拥有第一张图片中的设计,同时可以选择在键盘打开时调整它......
    • 尝试将线性布局上方的微调器与按钮对齐,并将线性布局与屏幕底部对齐。我认为这应该可以解决非键盘视图。使用键盘,看看这些变化看起来有多糟糕。真正的问题是它无法调整固定大小的 EditText。尝试确保该元素具有 layoutBelow 和 layoutAbove 并将其高度设置为 fill_parent- 应该使其在布局其余元素后占用剩余空间。
    • 我会试试这个,然后再回复你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    • 2018-01-07
    • 2013-02-14
    相关资源
    最近更新 更多