Listview changes the position of other views when you open the keyboard

I created an android screen with LinearLayoutin which I used the layout_sum property to split the screen. In this created EditTextfor search in ListView, it seems, before opening the soft keyboard. But when I open the soft keyboard EditText, you can hide as shown in the images.

Here is my xml code.

 <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>

Screen before opening the keyboard

enter image description here

after opening the keyboard

enter image description here

Any help would be assigned. Thanks.

+4
source share
4 answers

Do not use LinearLayout weight over ListView, i.e. use fixed height and set weight as 1 for ListView.

Edit:

code example:

<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>
+4

android:windowSoftInputMode="adjustPan" .

0

in your activity tag add as below

<activity
    android:name="com.companyname.applicationname"
    android:windowSoftInputMode="adjustPan">

See the link for more details.

0
source

Remove weight in listView and LinearLayout, use wrap_content like this

 <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="wrap_content"            
            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: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="wrap_content"            
            android:transcriptMode="normal" >
        </ListView>
</LinearLayout>
0
source

All Articles