【问题标题】:Soft Keyboard hides ListView elements in Fragment [duplicate]软键盘隐藏片段中的 ListView 元素 [重复]
【发布时间】:2016-01-25 12:05:57
【问题描述】:

我有一个包含 ListView 的片段,当我选择键盘按预期显示的第二个 EditText 时,我向其中添加了三个 EditText 和一个 Spinner,但我无法将列表视图滚动到列表视图中的最后两个剩余元素键盘是可见的。

几乎就像列表视图无法识别软键盘可见,最后两个剩余元素仍在软键盘后面。

以下是相关视图的屏幕截图和 XML。

AndroidManifest:

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan">

列表视图:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity$PlaceholderFragment"
android:background="@color/generic_grey">

<ListView
    android:id="@+id/form_base_listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="@null"
    android:dividerHeight="0dp"
    android:descendantFocusability="afterDescendants"
    />
</RelativeLayout>

多行视图:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingBottom="5dp">

<TextView
    android:id="@+id/form_multi_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/testing"
    android:padding="10dp"/>

<EditText
    android:id="@+id/form_multi_edit"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:layout_below="@+id/form_multi_txt"
    android:layout_marginLeft="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:background="@drawable/edit_text_background"
    android:layout_toLeftOf="@+id/form_multi_info_btn"
    android:layout_toStartOf="@+id/form_multi_info_btn"
    android:inputType="textMultiLine"/>

<ImageButton
    android:id="@+id/form_multi_info_btn"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:scaleType="fitStart"
    android:src="@drawable/form_row_info"
    android:background="@android:color/transparent"
    android:layout_below="@+id/form_multi_txt"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"/>

</RelativeLayout>

微调器:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingBottom="5dp">

<TextView
    android:id="@+id/form_select_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/testing"
    android:padding="10dp"/>

<Spinner
    android:id="@+id/form_select_spinner"
    android:layout_width="fill_parent"
    android:layout_height="44dp"
    android:layout_below="@+id/form_select_txt"
    android:layout_marginLeft="5dp"
    android:spinnerMode="dialog"
    android:layout_toLeftOf="@+id/form_select_info_btn"
    android:layout_toStartOf="@+id/form_select_info_btn"
    android:background="@android:drawable/btn_dropdown"
    />

<ImageButton
    android:id="@+id/form_select_info_btn"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:scaleType="fitStart"
    android:src="@drawable/form_row_info"
    android:background="@android:color/transparent"
    android:layout_below="@+id/form_select_txt"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"/>

</RelativeLayout>

微调器内的视图:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textViewSpinnerItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
style="@style/SpinnerTextViewItem"
/>

完整视图:

使用键盘查看:(无法滚动查看最后两个元素)

【问题讨论】:

  • 对清单文件中的活动使用 softInputMode=adjust pan
  • 我的清单里已经有这个了

标签: android listview android-softkeyboard


【解决方案1】:

将所有标签放在一个Realtive Layout中,将Relative Layout放在ScrollView中。因为 ScrollView 只需要一个孩子。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingBottom="5dp">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
    android:id="@+id/form_multi_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/testing"
    android:padding="10dp"/>

<EditText
    android:id="@+id/form_multi_edit"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:layout_below="@+id/form_multi_txt"
    android:layout_marginLeft="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    android:background="@drawable/edit_text_background"
    android:layout_toLeftOf="@+id/form_multi_info_btn"
    android:layout_toStartOf="@+id/form_multi_info_btn"
    android:inputType="textMultiLine"/>

<ImageButton
    android:id="@+id/form_multi_info_btn"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:scaleType="fitStart"
    android:src="@drawable/form_row_info"
    android:background="@android:color/transparent"
    android:layout_below="@+id/form_multi_txt"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

【讨论】:

    【解决方案2】:

    这是因为您的活动布局需要在软键盘打开后进行调整,而您没有设置。您需要做的是编辑您的 Manifest 并添加

    android:windowSoftInputMode="adjustResize"
    

    向右&lt;activity&gt; 标签。这是文档中的Handling Input Method Visibility 章节,您可能需要阅读以了解您可以使用windowSoftInputMode 设置哪些行为

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 2014-10-29
      • 2015-09-29
      • 1970-01-01
      相关资源
      最近更新 更多