Linearlayout Over Other Linearlayout

Asked

Viewed 982 times

2

I have a layout in Android Studio that I would like to have on another layout, but I can’t do it in any way. I would like you to be on top, because it is a menu that appears when someone presses the change image button.

Layout:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewController.ConfiguracaoViewController"
android:background="#FFF"
android:weightSum="1">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme">
        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:fitsSystemWindows="true"
            android:id="@+id/toolbar"
            >

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/voltar"
                android:layout_gravity="start"
                android:background="@android:color/transparent"
                android:drawableStart="@drawable/voltar"
                android:id="@+id/voltar_btn"
                android:textColor="#FFF"
                android:onClick="Voltar"
                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/configuracao"
                android:textAlignment="center"
                android:textSize="22sp"
                android:textColor="#FFF"
                android:paddingStart="0dp"
                android:paddingEnd="100dp"
                />

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <io.codetail.widget.RevealFrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <include layout="@layout/menu_anexo"/>
    </io.codetail.widget.RevealFrameLayout>





    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="125dp"
        android:layout_marginTop="10dp"
        android:layout_gravity="center">
        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/usuario_image"
            android:src="@drawable/muscleman"
            android:layout_marginStart="15dp"
            android:layout_marginTop="10dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/nome_do_usuario"
            android:id="@+id/nome_usuario_text"
            android:layout_marginTop="35dp"
            android:layout_marginStart="10dp"
            android:textSize="19sp"
            android:textColor="#000"/>
    </LinearLayout>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/sincronizar"
        android:id="@+id/sincronizar_btn"
        android:layout_gravity="center_vertical"
        android:layout_marginTop="10dp"
        android:background="#22BB5B"
        android:onClick="Sincronizar"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/trocar_senha"
        android:id="@+id/trocar_senha_btn"
        android:layout_gravity="center_vertical"
        android:layout_marginTop="10dp"
        android:background="#22BB5B"
        android:onClick="TrocarSenha"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/trocar_fofo"
        android:id="@+id/trocar_foto"
        android:layout_gravity="center_vertical"
        android:layout_marginTop="10dp"
        android:background="#22BB5B"
        android:onClick="TrocarFoto"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/politica_privacidade"
        android:id="@+id/politica_privacidade_btn"
        android:layout_gravity="center_vertical"
        android:layout_marginTop="10dp"
        android:background="#22BB5B"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/sair"
        android:id="@+id/sair_btn"
        android:layout_gravity="center_vertical"
        android:layout_marginTop="30dp"
        android:background="#22BB5B"/>
</LinearLayout>

How Design Behaves:

inserir a descrição da imagem aqui

  • Have you tried Relativelayout? Linearlayout forces objects to group vertically or horizontally, not letting them fall under each other, with Relative maybe you can.

  • What you want won’t be a Dialog?

2 answers

3


It is possible to insert a LinearLayout over another LinearLayout using RelativeLayout. The RelativeLayout is a layout that organizes its components relatively and is one of the Layout most used in Android. The position of each of the components can be specified according to the relation of the "sibling" element (such as to the left, from or below another point of view).

Relative Layout : Organizes the elements relative to another or parent

inserir a descrição da imagem aqui

Example

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >
    <LinearLayout
        android:id="@+id/name"
        android:layout_width="300dp"
        android:layout_height="400dp" />

  <LinearLayout
        android:id="@+id/name"
        android:layout_width="200dp"
        android:layout_height="300dp" />

</RelativeLayout>

Details

  • 1

    You’re right when you say RelativeLayout "is a layout that organizes its components relatively" and that "The position of each of the components can be specified according to the relation of the "sibling" element, however its example does not use any of the relative positioning attributes. Thus, if it replaces RelativeLayout for FrameLayout the result is the same.

  • 1

    @I do not even use any attribute, and for this very reason the first LinearLayout will be superimposed on the second LinearLayout, which is exactly the solution of the question. But you are also right in saying that the FrameLayout result the same thing. Thinking like this, maybe, I say maybe it is a more viable solution to use FrameLayout. Thank you for your attention.

  • I didn’t know the Relativelayout yet, very useful by the way. Thank you very much for the help.

0

use setVisibility you leave visible or not the layout you want to show to the user depending on the action of it.

setVisibility

Browser other questions tagged

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