I need to squeeze my layout when I open the keyboard

Asked

Viewed 1,713 times

1

I’m wearing a TableLayout that contain EditText, and when the focus is on EditText the keyboard opens and stands in front of important information, would like to be able to squeeze the layout when opening the keyboard. For my entire layout (which previously occupied the entire screen) stay whole visible with the keyboard open. This is possible?

Can someone give me some tips or show me a literature/tutorial?

<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:background="#000000"
    android:orientation="vertical"
    tools:context="com.example.app.MainActivity" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:weightSum="4" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:weightSum="1" >

            <EditText
                android:id="@+id/etdescricao"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#000000" >

            <EditText
                android:id="@+id/etl5"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="5" >

            <EditText
                android:id="@+id/et1"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/etl1"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/etl2"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/etl3"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et4"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/etl4"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et5"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#000000" >

            <EditText
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="5" >

            <EditText
                android:id="@+id/et6"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et7"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et8"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et9"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et10"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#000000" >

            <EditText
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="5" >

            <EditText
                android:id="@+id/et11"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et12"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et13"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et14"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />

            <EditText
                android:id="@+id/et15"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffffff"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#000000" >

            <EditText
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#000000"
                android:maxLength="100"
                android:maxLines="2" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="5" >

            <Button
                android:id="@+id/btSalvar"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/btn_selector"
                android:text="Salvar"
                android:textColor="#ffffff"
                android:textSize="30sp" />

            <Button
                android:id="@+id/BtPrevious2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/btn_selector"
                android:text="@string/previous"
                android:textColor="#ffffff"
                android:textSize="30sp" />

            <Button
                android:id="@+id/tvp2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#000000"
                android:singleLine="true"
                android:textColor="#ff0000"
                android:textSize="75sp" />

            <Button
                android:id="@+id/btNext2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/btn_selector"
                android:text="@string/Next"
                android:textColor="#ffffff"
                android:textSize="30sp" />

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#000000"
                android:src="@drawable/logostar" />
            <!-- android:background="#000000" -->

        </TableRow>
    </TableLayout>
</LinearLayout>
  • You want your layout to resize when the keyboard appears?

  • yes, make it smaller, so that the screen is always visible. I want to decrease the length of the lines so that when it appears the keyboard n adds nothing.

  • but at the same time I want to leave self-adjusting for different screen sizes... I will post my xml

  • did not want the buttons to disappear nor the page number and this to edit all edittext without closing the keyboard

  • Expremer the layout would be a bad result, in cell phones that have the small screen would lose a lot in visual quality , ocerto is encapsulate its layout within a scrollview equal to Cícero Moura replied.

  • @Juarez The application is only for tablets, but Valew, I think I’ll do yes.

Show 1 more comment

2 answers

2


What you can do is put your layout inside a Scrollview and when the keyboard opens, the user can scroll the layout to see the information you want.

Would look like this:

<ScrollView 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"
    tools:context="com.example.app.MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000"
        android:orientation="vertical" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="4" >

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:weightSum="1" >

                <EditText
                    android:id="@+id/etdescricao"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000" >

                <EditText
                    android:id="@+id/etl5"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:weightSum="5" >

                <EditText
                    android:id="@+id/et1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/etl1"
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/etl2"
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et3"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/etl3"
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et4"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/etl4"
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et5"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000" >

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:weightSum="5" >

                <EditText
                    android:id="@+id/et6"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et7"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et8"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et9"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et10"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000" >

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:weightSum="5" >

                <EditText
                    android:id="@+id/et11"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et12"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et13"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et14"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />

                <EditText
                    android:id="@+id/et15"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#ffffff"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#000000" >

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#000000"
                    android:maxLength="100"
                    android:maxLines="2" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:weightSum="5" >

                <Button
                    android:id="@+id/btSalvar"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/btn_selector"
                    android:text="Salvar"
                    android:textColor="#ffffff"
                    android:textSize="30sp" />

                <Button
                    android:id="@+id/BtPrevious2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/btn_selector"
                    android:text="@string/previous"
                    android:textColor="#ffffff"
                    android:textSize="30sp" />

                <Button
                    android:id="@+id/tvp2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#000000"
                    android:singleLine="true"
                    android:textColor="#ff0000"
                    android:textSize="75sp" />

                <Button
                    android:id="@+id/btNext2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/btn_selector"
                    android:text="@string/Next"
                    android:textColor="#ffffff"
                    android:textSize="30sp" />

                <ImageButton
                    android:id="@+id/imageButton1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#000000"
                    android:src="@drawable/logostar" />
                <!-- android:background="#000000" -->

            </TableRow>
        </TableLayout>
    </LinearLayout>

</ScrollView>
  • yes perfect, the problem is that now it does not come back!!

  • Since it doesn’t come back, the keyboard doesn’t come back?

  • the keyboard back, what does not come back is the layout, it gets expressed

  • Take a look at this answer: http://stackoverflow.com/questions/16411056/how-to-adjust-layout-when-soft-keyboard-appears

0

An attribute that would work for your case is android:layout_alignParentBottom="true", What he does is line up view always on the keyboard (when it appears).

But you need to be using RelativeLayout.

You want more information and examples?

Link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.