1

I'm designing a simple login activity. I've used the following xml layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_vertical|center_horizontal"
        android:layout_margin="15dp">
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My application title"
            android:textSize="30sp"/>
    </LinearLayout>

     <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="vertical"
        android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_vertical"
        android:layout_margin="15dp">
          <EditText 
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="Username"/>      
          <EditText 
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="Password"
              android:layout_marginTop="15dp"/>
          <Button 
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="15dp"
              android:text="Login"/>
     </LinearLayout>

</LinearLayout>

And I've obtained this result:

enter image description here

But If the focus is on the first EditText I obtain this:

enter image description here

and If the focus is on the second EdiText the result is the follwoing:

enter image description here

Considering I've used the following line in the Manifest, for my activity:

android:windowSoftInputMode="adjustPan|adjustResize"

I want that when the virtual keyboard appears, the two edittext, the button and the textview are visible and correctly centered in the available screen. What I have to change in my code?

NOTE: I've the same result If I remove the line in the manifest:

android:windowSoftInputMode="adjustPan|adjustResize"
Cœur
  • 37,241
  • 25
  • 195
  • 267
GVillani82
  • 17,196
  • 30
  • 105
  • 172

1 Answers1

1

You can replace the parent LinearLayout to a ScrollView :

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

  <LinearLayout ...>

  ....
  ....

  </LinearLayout>


</ScrollView>

try this, it works for some of my apk !

Edit : sorry didn't see about center the text automaticaly, so with this you can adjust manually your editext to center with swipe your finger.. hope that will help

Nemka
  • 100
  • 11