Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep background image size when software keyboard show

Tags:

When the software keyboard shows, it resizes my layout and thus squeezes the background image together. My question is basically a duplicate of this question, which is explained in a very good way:

Software keyboard resizes background image on Android

However, that question was closed when they found a hack to solve it. I cannot use this hack. My entire layout is inside a ScrollView, and I need to be able to use this scrollview properly at all times. By using android:windowSoftInputMode="stateVisible|adjustPan" the user will not be able to scroll down and see the bottom of the screen while the keyboard is showing, since the layout will partly exist behind the keyboard. Thus the solution is unacceptable to me. Are there any better solutions out there?

Cheers,

like image 637
pgsandstrom Avatar asked May 11 '11 14:05

pgsandstrom


2 Answers

I actually ran into a similar problem not too long ago. I stumbled upon the correct answer with a bit of work, though.

In your android manifest for this project, attached to the specific activity that you are using, use the line android:windowSoftInputMode="adjustPan|stateVisible" in the activity tag.

adjustPan basically means that your activity will not resize itself to fit the soft keyboard, and stateVisible means that the soft keyboard will show when requested (this can be stateAlwaysVisible, etc if necessary)

source : Android Dev for Activity tags

like image 91
syklon Avatar answered Oct 13 '22 03:10

syklon


After days of hardcore hacking I finally managed to construct a solution so advanced it might actually hurt to read it. I place an ImageView with the background behind the scrollview, and set scaleType="matrix" so it does not shrink when the keyboard is shown.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/black"
    >
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/mah_kewl_background"
        android:scaleType="matrix"
        />
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        >
        <RelativeLayout
            android:id="@+id/smsLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="PLUNX"
                />
        </RelativeLayout>
    </ScrollView>
</RelativeLayout>
like image 34
pgsandstrom Avatar answered Oct 13 '22 04:10

pgsandstrom