mardi 26 mai 2015

How can I correctly resize the layout when the keyboard appears?

In Android I have reproduced the following layout :

enter image description here

In this way :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#94F734"
    android:orientation="vertical">

<LinearLayout  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="48dp"
    android:layout_marginLeft="48dp"
    android:padding="0dp">
    <include 
        layout="@layout/header"/>
</LinearLayout>

  <RelativeLayout 
    android:id="@+id/body"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="48dp"
    android:layout_marginRight="48dp"
    android:layout_marginBottom="48dp"
    android:paddingTop="96dp"
    android:background="#463779B3"
    android:visibility="visible"
   >

       <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textSize="28dp"
        android:text="title"
        android:layout_above="@+id/code"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="48dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:textColor="#000000"
     />

    <EditText
        android:id="@+id/code"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Insert here "
        android:background="@drawable/back_item_edit"
        android:textColor="#FFFFFF"
        android:layout_centerVertical="true"
        android:layout_marginLeft="36dp"
        android:layout_marginRight="36dp">
     <requestFocus />

    </EditText>

    <Button
        android:id="@+id/prova"
        android:layout_below="@id/code"
        style="@style/initialButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="26dp"
        android:text="Connect"
        android:textColor="#000000"
        android:layout_alignLeft="@id/code"
        android:layout_alignRight="@id/code"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:visibility="visible"
         />



    </RelativeLayout>






</LinearLayout>

But when I click on "insert here" one problem appears : the layout is not correctly resized and doesn't fit in the little screen.

I thought to use a scrollview, but I don't know how to use it.

WHen the keyboard appears I would to show :

  • header (if there is room)
  • title (if there is room)
  • insert here
  • connect
  • green part of layout (if there is room)
  • keyboard

Is there a way to resolve my problem ?

Aucun commentaire:

Enregistrer un commentaire