android - Listview改变键盘打开其他 View 的位置

标签 android xml layout

我使用 LinearLayout 创建了 android 屏幕,其中我使用 layout_sum 属性进行屏幕划分。在创建一个 EditText 用于在 ListView 中搜索时,在打开软键盘之前似乎没问题。 但是,当我打开软键盘时,EditText 会像图像中显示的那样隐藏。

这是我的 xml 代码。

 <LinearLayout 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"
        android:orientation="vertical"
        android:weightSum="3"
        >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.9"
            android:orientation="vertical" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4" >
    
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_margin="3dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="T100"
                    android:textSize="12sp"
                    android:textStyle="bold" />
    
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_margin="3dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="A100"
                    android:textSize="12sp"
                    android:textStyle="bold" />
    
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_margin="3dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="P100"
                    android:textSize="12sp"
                    android:textStyle="bold" />
    
                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_margin="3dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="S100"
                    android:textSize="12sp"
                    android:textStyle="bold" />
            </LinearLayout>
    
              <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                android:weightSum="4" >
    
                <TextView
                    android:id="@+id/txtSearch"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_below="@id/lvdetail"
                    android:text="Search :" 
                    android:layout_weight="1"
                    android:gravity="center"/>
    
                <EditText
                    android:id="@+id/eatmcode"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:ems="2"
                    android:focusableInTouchMode="true"
                    android:hint="Enter ATM"
                    android:imeOptions="actionSearch"
                    android:inputType="text"
                    android:textSize="16dp" 
                    android:layout_weight="2"/>
            </LinearLayout> 
    
            <TextView
                android:id="@+id/txtLabel"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtSearch"
                android:layout_marginBottom="10dp"
                android:gravity="center_horizontal"
                android:paddingTop="10dp"
                android:text="List of Vehicle"
                android:textSize="14dp"
                android:textStyle="bold" /> 
        </LinearLayout>
    
        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2.1"
            android:transcriptMode="normal" >
        </ListView>
    
    </LinearLayout>

键盘打开前的画面

enter image description here

键盘打开后

enter image description here

任何帮助都将得到应用。谢谢。

最佳答案

ListView上方的LinearLayout不要使用weight,即使用固定高度,ListView的weight设置为1。

编辑:

示例代码:

<LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:orientation="vertical" >

       ...

    </LinearLayout>

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:transcriptMode="normal" >
    </ListView>

</LinearLayout>

关于android - Listview改变键盘打开其他 View 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32311991/

相关文章:

java - 如何将按钮添加到 borderlayout 右下角的 java 应用程序按钮?

Android 初学者 - 包装和纯文本 - Eclipse/Android Studio

java - 设置 NetworkImageView 与 Volley 禁用图像的持有者

java - 使用 RTL 语言的正则表达式

android - onBackPressed() 方向问题

c - XML 文档如何与 GTK 一起工作来创建用户界面?

c# - Visual Studio 尖括号 alt gr 不起作用

java - 获取带有挂起 Intent 的位置更新会返回空位置

java - 使用 java 和 XPath 搜索 xml 文档中的属性

python - 如何将此 XML 解析为 python 数组或字典?