Resize ListView when keyboard is present

I have a little problem resizing my list when there is a software keyboard. Basically, I am using google maps api where the map covers the whole screen, with a transparent action bar and I have a list of cars present on the map in a fragment that slides from the right side. When the right pane comes out, the whole layout looks like this:enter image description here

Now I use android:windowSoftInputMode="adjustPan"

, so when I focus my text and slide editing on the keyboard it looks like this:enter image description here

This is not good because I cannot see the whole cars. I tried to use android:windowSoftInputMode="adjustResize"

, but since I am using a transparent action bar, this happens: enter image description here I can see the whole ListView and it scrolls nicely, but my EditText is now under the ActionBar. Basically what I want to achieve is a combination of both, so it would look like this: enter image description here Now this is the layout for the snippet with my list

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="@drawable/bg"
    tools:context="hidden">

    <EditText
        android:id="@+id/vehicle_search_edit_text"
        android:layout_width="fill_parent"
        android:layout_height="45dp"
        android:focusable="true"
        android:hint="Search"
        android:imeOptions="actionSearch"
        android:singleLine="true" />

    <ListView
        android:id="@+id/list_vehicles"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/vehicle_search_edit_text"
        android:animateLayoutChanges="true"
        android:fastScrollEnabled="true"
        />
</RelativeLayout>

      

And this is the layout of my MainActivity

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/layout_root_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:id="@+id/layout_root_vehicles"
        android:layout_width="350dp"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

    <RelativeLayout
        android:id="@+id/layout_root_settings"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

</RelativeLayout>

      

I am familiar with setting the height of a layout programmatically, since I already do this with a layout in which the listfragment is nested. The ActionBar should remain transparent because that's what my boss wants. I've searched for a solution all day, but couldn't find anything for me, so I would be very grateful for any help.

+3


source to share


4 answers


I believe that since your action screen is similar to the one used by Google Maps, for example the space it normally occupies is considered available for use by other layouts, in your case, a fragment. You force cork and set padding or margins for your fragment container, for example:

android:paddingTop="?android:attr/actionBarSize"

      

(action bar size).

Together with



android:windowSoftInputMode="adjustResize"

      

this should work.

This padding value does not suit you, manually specify a more appropriate value.

+3


source


In your manifest file add android:windowSoftInputMode="adjustPan"

to your activity. For example,

<activity
            android:name="com.sample.ListViewsActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan" >
        </activity>

      



I think this solves your problem. Just try it.

0


source


The API says the following http://developer.android.com/reference/android/widget/ListView.html

TRANSCRIPT_MODE_ALWAYS_SCROLL = The list will automatically scroll to the bottom, no matter what items are currently visible.

setTranscriptMode (int mode) = Sets the list or grid to transcription mode.

Please check if it works!

setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

      

...

0


source


in AndroidManifest.xml add:

<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize"/>
</activity> 

      

for your activity and add two parameters:

<ListView
android:stackFromBottom="true"
android:transcriptMode="normal"/>

      

0


source







All Articles