Layout does not fit on the screen after rotation

Asked

Viewed 609 times

2

I developed an application that works normally but when I turn the screen to landscape orientation the app is cut and not to go down and view the rest of the content and also the Admob I implemented only works on the vertical screen, horizontal does not display ads, which can be?

Vertical:

inserir a descrição da imagem aqui

Horizontal:

inserir a descrição da imagem aqui

2 answers

5


One of the ways to solve your problem is to insert your content into a Scrollview, respectively allows the vertical scroll bar. And another way for you to solve is Exploring the Smartphone Orientation.

1. Scrollview

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

    <LinearLayout 
        android:id="@+id/layout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!-- 
         Aqui será exibia nossa lista
         -->

    </LinearLayout>
</ScrollView>

For more insight, note the image below the Scrollview and Horizontalscrollview schema:

inserir a descrição da imagem aqui

This link has an easy example to help you do that.

2. Exploring the Orientation

As suggested in the comments, you can create two different layouts according to the orientation of the smartphone.

res/
    layout/              # default (portrait)
        main.xml
    layout-land/         # landscape
        main.xml
    layout-large/        # large (portrait)
        main.xml
    layout-large-land/   # large landscape
        main.xml

inserir a descrição da imagem aqui

Read here in the Android documentation about Supporting Different Screens that you’ll have more sense.

  • Another possibility, perhaps better, is to use two "layouts", one for the canvas horizontally and the other for the canvas vertically.

  • 1

    Yes @ramaral , I rectified the answer to improve understanding and show that there are other possibilities.

  • 1

    Excellent response!

  • 1

    managed to solve! thanks.

0

You can create two layout or use scrool view as below!

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<ScrollView android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/scrollView"
    android:layout_marginTop="40dp">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:weightSum="1"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="150px"
            android:src="@drawable/ico_login"
            android:layout_marginTop="100px"
            />

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="90px"
            android:id="@+id/edtEmailLogin"
            android:hint="@string/emailUsuario"
            android:drawableLeft="@android:drawable/ic_dialog_email"
            android:textAlignment="center"
            android:layout_marginBottom="15dp"
            />

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="90px"
            android:inputType="textPassword"
            android:id="@+id/edtSenhaLogin"
            android:hint="@string/senhaUsuario"
            android:drawableLeft="@android:drawable/ic_lock_idle_lock"
            android:textAlignment="center"
            android:layout_marginBottom="15dp"

            />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="1"
            android:baselineAligned="false"
            android:layout_marginBottom="15dp"
            android:gravity="center">

            <Button
                android:layout_width="143dp"
                android:layout_height="wrap_content"
                android:id="@+id/btnEntrar"
                android:text="@string/botaoEnviar"
                android:onClick="setContentView"

                />

            <Button
                android:layout_width="143dp"
                android:layout_height="wrap_content"
                android:id="@+id/btnCancelar"
                android:text="@string/botaoCancelar"
                android:onClick="setContentView"
                android:layout_weight="0.27"

                />

        </LinearLayout>

    </LinearLayout>
</ScrollView>

Browser other questions tagged

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