Layout does not occupy full screen

Asked

Viewed 1,010 times

1

I’m putting together a layout and the layout isn’t occupying the entire screen. I’ve tried it in many ways, but it’s never possible that it will, so it’s not fitting everything I need.

Problem happens when placing the scrollview, it is possible to have the whole screen, with it?

Follows XML:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:id="@+id/relative_rota">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="vertical"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="15dp">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="0dp"
            android:layout_marginStart="@dimen/txt_left_margin"
            android:layout_marginTop="@dimen/first_view_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:text="@string/ondeEstou"
            android:textColor="@color/txt_text"
            android:textStyle="bold" />


        <AutoCompleteTextView
            android:id="@+id/rota_edt_origem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:layout_marginEnd="@dimen/edt_right_margin"
            android:layout_marginStart="@dimen/edt_left_margin"
            android:layout_marginTop="@dimen/edt_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:hint="@string/action_my_location"
            android:inputType="textCapCharacters"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="@color/edt_text"
            android:textColorHint="@color/edt_text"
            android:textSize="@dimen/edt_text_size" />


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/txt_left_margin"
            android:fontFamily="sans-serif-condensed"
            android:text="@string/destino"
            android:textColor="@color/txt_text"
            android:textStyle="bold" />

        <AutoCompleteTextView
            android:id="@+id/rota_edt_destino"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/edt_right_margin"
            android:layout_marginStart="@dimen/edt_left_margin"
            android:layout_marginTop="@dimen/edt_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:inputType="textCapCharacters"
            android:hint="@string/action_type_destination"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="@color/edt_text"
            android:textColorHint="@color/edt_text"
            android:textSize="@dimen/edt_text_size"
            android:layout_marginBottom="7dp"/>


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/txt_left_margin"
            android:fontFamily="sans-serif-condensed"
            android:text="@string/companhia"
            android:textColor="@color/txt_text"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/rota_edt_companhia"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:layout_marginEnd="@dimen/edt_right_margin"
            android:layout_marginStart="@dimen/edt_left_margin"
            android:layout_marginTop="@dimen/edt_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:inputType="none"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="@color/edt_text"
            android:textIsSelectable="true"
            android:textSize="@dimen/edt_text_size" />

    </LinearLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:completionThreshold="3"
        android:src="@drawable/powered_by_google_light"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center_horizontal"
        android:layout_alignParentStart="true"
        android:layout_marginTop="124dp">

        <ImageButton
            android:id="@+id/trasporte_a_pe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_walk_white_48px" />

        <ImageButton
            android:id="@+id/trasporte_bike"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_bike_white_48px" />

        <ImageButton
            android:id="@+id/trasporte_carro"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_car_white_48px" />


        <ImageButton
            android:id="@+id/trasporte_publico"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_bus_white_48px" />

    </LinearLayout>
</RelativeLayout>

Follows image of how it is:

inserir a descrição da imagem aqui

I need you to take the whole screen, so it’s well distributed. Only vertically same.

thanks for the help!

-EDIT- XML changed, but when placing the scrollview, so that it is possible to scroll the screen with the keyboard open, it limits me to the marked image.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative_rota"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fundo_3"
    android:padding="10dp"
    tools:context="app.Rota">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/layout_top"
        android:layout_gravity="end"
        android:completionThreshold="3"
        android:src="@drawable/powered_by_google_light" />

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="115dp"
        android:gravity="center_horizontal"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/trasporte_a_pe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:background="@color/fundo_3"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_walk_white_48px" />

        <ImageButton
            android:id="@+id/trasporte_bike"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:background="@color/fundo_3"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_bike_white_48px" />

        <ImageButton
            android:id="@+id/trasporte_carro"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:background="@color/fundo_3"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_car_white_48px" />


        <ImageButton
            android:id="@+id/trasporte_publico"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:background="@color/fundo_3"
            android:contentDescription="@string/place_autocomplete_search_hint"
            android:onClick="chamarRota"
            android:padding="@dimen/place_autocomplete_button_padding"
            android:src="@drawable/ic_transp_bus_white_48px" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="80dp"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="0dp"
            android:layout_marginStart="@dimen/txt_left_margin"
            android:layout_marginTop="@dimen/first_view_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:text="@string/ondeEstou"
            android:textColor="@color/txt_text"
            android:textStyle="bold" />


        <AutoCompleteTextView
            android:id="@+id/rota_edt_origem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:layout_marginEnd="@dimen/edt_right_margin"
            android:layout_marginStart="@dimen/edt_left_margin"
            android:layout_marginTop="@dimen/edt_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:hint="@string/action_my_location"
            android:inputType="textCapCharacters"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="@color/edt_text"
            android:textColorHint="@color/edt_text"
            android:textSize="@dimen/edt_text_size" />


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/txt_left_margin"
            android:fontFamily="sans-serif-condensed"
            android:text="@string/destino"
            android:textColor="@color/txt_text"
            android:textStyle="bold" />

        <AutoCompleteTextView
            android:id="@+id/rota_edt_destino"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:layout_marginEnd="@dimen/edt_right_margin"
            android:layout_marginStart="@dimen/edt_left_margin"
            android:layout_marginTop="@dimen/edt_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:hint="@string/action_type_destination"
            android:inputType="textCapCharacters"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="@color/edt_text"
            android:textColorHint="@color/edt_text"
            android:textSize="@dimen/edt_text_size" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/txt_left_margin"
            android:fontFamily="sans-serif-condensed"
            android:text="@string/companhia"
            android:textColor="@color/txt_text"
            android:textStyle="bold" />

        <EditText
            android:id="@+id/rota_edt_companhia"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="7dp"
            android:layout_marginEnd="@dimen/edt_right_margin"
            android:layout_marginStart="@dimen/edt_left_margin"
            android:layout_marginTop="@dimen/edt_top_margin"
            android:fontFamily="sans-serif-condensed"
            android:inputType="none"
            android:maxLines="1"
            android:singleLine="true"
            android:textColor="@color/edt_text"
            android:textIsSelectable="true"
            android:textSize="@dimen/edt_text_size" />

    </LinearLayout>
</RelativeLayout>
  • @Guilhermenascimento the problem is when I put the scrollview, would it be possible to do with scrollview? Because when I put it does not go to the whole screen.

  • @Guilhermenascimento if I don’t have the scrollview, I can do it according to the answer below. I can manipulate the layout all over the screen. But when I put the scrollview, for example being "father" of the entire layout, it limits me, in this small space of the image, managed to understand?

  • @I don’t know what a viewport is. The scrollview I would like it to be possible scroll through the whole screen, when the keyboard is open, so I believe it should be inside the relativelayout, I will put the XML, "new", but still without the scrollview.

  • Try to root scrollView, like Scrollview > Relativelayout > Linearlayout and do the rest as in the answer below.

  • @Guilhermenascimento I tried, I cannot understand why not let move the whole screen

  • It’s true, it does so remove Relative and leaves only Scrollview > Linearlayout, see if it works, is that I am without androidstudio here, but tomorrow in the office I will test also anything ;)

  • @Guilhermenascimento Since scrollview can only have one "son" I added another linear layout, vertically, it really gives me a larger work area and better distribution of the screen. But even so, it is not the whole screen, but it has improved a lot! And quiet, here is no hurry haha was worth too much already!

Show 2 more comments

1 answer

2


Since I don’t have your drawables and values, and you haven’t shown exactly how you’d like the layout to look, I improvised on top of the code. I put colors in the background of the layouts (to differentiate) and used Studio images.

Compare the two to understand where you got it wrong.

<RelativeLayout 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:padding="10dp"
android:id="@+id/relative_rota">

<LinearLayout
    android:id="@+id/layout_top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="15dp"
    android:background="@android:color/holo_green_dark">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:layout_marginStart="@dimen/txt_left_margin"
        android:layout_marginTop="@dimen/first_view_top_margin"
        android:fontFamily="sans-serif-condensed"
        android:text="@string/ondeEstou"
        android:textColor="@color/txt_text"
        android:textStyle="bold" />


    <AutoCompleteTextView
        android:id="@+id/rota_edt_origem"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:layout_marginEnd="@dimen/edt_right_margin"
        android:layout_marginStart="@dimen/edt_left_margin"
        android:layout_marginTop="@dimen/edt_top_margin"
        android:fontFamily="sans-serif-condensed"
        android:hint="@string/action_my_location"
        android:inputType="textCapCharacters"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="@color/edt_text"
        android:textColorHint="@color/edt_text"
        android:textSize="@dimen/edt_text_size" />


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/txt_left_margin"
        android:fontFamily="sans-serif-condensed"
        android:text="@string/destino"
        android:textColor="@color/txt_text"
        android:textStyle="bold" />

    <AutoCompleteTextView
        android:id="@+id/rota_edt_destino"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/edt_right_margin"
        android:layout_marginStart="@dimen/edt_left_margin"
        android:layout_marginTop="@dimen/edt_top_margin"
        android:fontFamily="sans-serif-condensed"
        android:inputType="textCapCharacters"
        android:hint="@string/action_type_destination"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="@color/edt_text"
        android:textColorHint="@color/edt_text"
        android:textSize="@dimen/edt_text_size"
        android:layout_marginBottom="7dp"/>


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/txt_left_margin"
        android:fontFamily="sans-serif-condensed"
        android:text="@string/companhia"
        android:textColor="@color/txt_text"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/rota_edt_companhia"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="7dp"
        android:layout_marginEnd="@dimen/edt_right_margin"
        android:layout_marginStart="@dimen/edt_left_margin"
        android:layout_marginTop="@dimen/edt_top_margin"
        android:fontFamily="sans-serif-condensed"
        android:inputType="none"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="@color/edt_text"
        android:textIsSelectable="true"
        android:textSize="@dimen/edt_text_size" />

</LinearLayout>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end"
    android:layout_centerInParent="true"
    android:completionThreshold="3"
    android:src="@drawable/common_google_signin_btn_icon_light_focused"
    android:background="@color/colorAccent" 
    android:id="@+id/image_view"
    android:layout_below="@+id/layout_top"/>

<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"

    android:background="@android:color/holo_orange_light">

    <ImageButton
        android:id="@+id/trasporte_a_pe"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:contentDescription="@string/place_autocomplete_search_hint"
        android:onClick="chamarRota"
        android:padding="@dimen/place_autocomplete_button_padding"
        android:src="@drawable/ic_transp_walk_white_48px"
        tools:src="?android:attr/actionModePasteDrawable" />

    <ImageButton
        android:id="@+id/trasporte_bike"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:contentDescription="@string/place_autocomplete_search_hint"
        android:onClick="chamarRota"
        android:padding="@dimen/place_autocomplete_button_padding"
        android:src="?attr/actionModeShareDrawable" />

    <ImageButton
        android:id="@+id/trasporte_carro"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:contentDescription="@string/place_autocomplete_search_hint"
        android:onClick="chamarRota"
        android:padding="@dimen/place_autocomplete_button_padding"
        android:src="?android:attr/actionModeCutDrawable" />


    <ImageButton
        android:id="@+id/trasporte_publico"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:contentDescription="@string/place_autocomplete_search_hint"
        android:onClick="chamarRota"
        android:padding="@dimen/place_autocomplete_button_padding"
        android:src="?android:attr/alertDialogIcon" />

</LinearLayout>

Some tips regarding code:

  1. Within Relativelayout, views are positioned IN RELATION TO EACH OTHER.
  2. In this case, the heights (height) of most views should be wrap_content, except for the root.
  3. layout_alignParent... does the ALIGNMENT with the parent view and does not touch the element dimensions.
  4. margin and padding are good for separating views from each other. Use to position relative to the parent view, especially using specific values, can cause problems like view overlay.
  5. Parent is not the previous view, but it is the parent view, within which the view is.
  • Layout was excellent, basically what I want. But I can’t do that with scrollview, because it would be good to have it, so you don’t always have to lower the keyboard to see the fields. It is possible to do this?

  • If I understand the question, you put the scrollview as viewgroup Parent that you want to scroll when there is not enough space. That is, you do not need to put out the relativelayout, being able to stay out of the linearlayout only

Browser other questions tagged

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