0

I've got a problem in my application.

My layout contains:

  • ImageView
  • Button
  • Four EditText

When I change the emulator in landscape mode the ScrollView goes to the third EditText. The last EditText is not displayed in landscape mode.

My layout.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="60dp"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="235dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:id="@+id/formulario_foto"
            android:background="#00A8EC"
            android:src="@drawable/person"/>

        <Button
            android:layout_width="56dp"
            android:layout_height="56dp"
            android:id="@+id/formulario_foto_button"
            android:layout_alignParentBottom='true'
            android:layout_alignParentRight="true"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="20dp"
            android:background="@drawable/formulario_foto_button"
            android:elevation="5dp"
            android:gravity="center"
            android:textColor="#FFFFFF"
            android:textSize="20sp"/>

    </RelativeLayout>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:hint="Nome"
        android:id="@+id/editTextNome" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:ems="10"
        android:hint="E-mail"
        android:id="@+id/editTextEmail" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:hint="Endereço"
        android:id="@+id/editTextEndereco" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:inputType="phone"
        android:ems="10"
        android:hint="Telefone"
        android:id="@+id/editTextTelefone" />

    </LinearLayout>
</ScrollView>
Luiz Henrique Ugliano
  • 1,317
  • 2
  • 13
  • 26

2 Answers2

3

It looks like ScrollView does not respect the margin of its child. This behavior has been noted in

The workaround is to wrap your LinearLayout in a FrameLayout, ie.

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="60dp"
        android:orientation="vertical">
    ...
    </LinearLayout>
</FrameLayout>

This is slightly inefficient, since it uses an extra ViewGroup. If you are able to do so, the more efficient solution would be to use paddingTop on your LinearLayout instead of the layout_marginTop, ie.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="60dp"
    android:orientation="vertical">
...
</LinearLayout>
Community
  • 1
  • 1
savanto
  • 4,470
  • 23
  • 40
0

Change linear layout height to wrap_content