R.H
R.H

Reputation: 318

Layout pushes up when keyboard popups

Whole layout pushes up when keyboard pops up. Xml file contains listview and below that two buttons, when keyboard popups both listview and buttons pushes up.

    <?xml version="1.0" encoding="utf-8"?>
    <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"
    tools:context="com.example.athis.buy.HomeScreen">

    <SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ListView
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="10dp"
        android:layout_weight="8"
        android:divider="#ffffff"
        android:dividerHeight="10dp"
        android:padding="5dp" />

    <LinearLayout
        android:id="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#a8b3ff"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:weightSum="100">

        <Button
            android:id="@+id/filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:layout_marginStart="10dp"
            android:layout_weight="50"
            android:text="Filter"
            android:layout_marginBottom="2dp"/>

        <Button
            android:id="@+id/sort"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="10dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:layout_marginStart="5dp"
            android:layout_weight="50"
            android:text="Sort"
            android:layout_marginBottom="2dp"/>
    </LinearLayout>
</LinearLayout>

I have added android:windowSoftInputMode="stateHidden" in manifest so that when i touch edittext only then keyboard should pop up

Upvotes: 1

Views: 60

Answers (2)

Mahmoud Sabbah
Mahmoud Sabbah

Reputation: 94

Add this on your activity on the Manifest

android:windowSoftInputMode="adjustPan"

Upvotes: 1

NotABot
NotABot

Reputation: 801

add windowSoftInputMode="adjustPan" attribute in your AndroidManifest.xml for that particular Activity. refer to this.

<activity
        android:name=".activities.YourActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />

Hope this helps. GL!

Upvotes: 1

Related Questions