出现软键盘时重叠片段

时间:2014-02-20 16:33:52

标签: android android-fragments android-softkeyboard

我有一个包含多个片段的活动,特别是:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="1056dp"
    android:layout_height="match_parent">
    <fragment
        android:layout_width="1056dp"
        android:layout_height="0dp"
        android:name="FragEntryEdit"
        android:id="@+id/itemEditFragment"
        tools:layout="@layout/fragment_entry_edit"
        android:layout_weight="2"
        />

    <ScrollView
        android:layout_width="1056dp"
        android:layout_height="0dp"
        android:layout_weight="1.5">
        <fragment
            android:layout_width="1056dp"
            android:layout_height="match_parent"
            android:name="FragPhotos"
            android:id="@+id/itemPhoto"
            tools:layout="@layout/fragment_photos"
            />
    </ScrollView>
</LinearLayout>

第一个片段包含一些EditText控件,其中一些控件是多行的。

创建时,我隐藏了软键盘。当editText控件获得焦点时,会出现软键盘。

然而,第二个片段(位于第一个片段下方)的内容被键盘向上推,与EditText控件(第一个片段)重叠。

我试图将'windowSoftInputMode'设置为'AdjustPan',但这似乎不起作用。

有人有任何建议吗?

2 个答案:

答案 0 :(得分:0)

我建议设置片段的背景。我有重叠片段的类似问题,我解决了它为片段设置白色背景。

my_fragment.xml

<?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="@android:color/white"
    android:orientation="vertical" >

    <!-- MORE XML -->

</LinearLayout>

答案 1 :(得分:0)

想出来! 问题不是碎片,而是LinearLayouts中的垂直加权。 我删除了加权并在第一个片段周围包裹了一个ScrollView,它可以工作。

相关问题