One component on top of the other

4

I have a problem that I do not think how to solve it, I have an activity like in the picture below, the problem is, that when I emulate the application, the Button and the textView go under the two colored LinearLayouts (blue and green).

IwouldliketoknowhowtoassignapropertyfortheButtonandthetextViewsothattheyareoverLayouts

Note:IdidnotwanttoputtheButtonandtextViewinsidethecoloredLayouts.

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.uriel.aaa.MainActivity">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">


        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00008B"/>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#008B45"/>
    </LinearLayout>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:elevation="@dimen/activity_vertical_margin"
        android:text="aaa"
        android:textColor="#FFFFFF"
        android:textSize="40sp"
        android:gravity="center_vertical"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/textView"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Testar"
        android:textSize="40sp"
        android:id="@+id/buttonStart"
        android:background="#FFFFFF"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
    
asked by anonymous 23.06.2016 / 22:54

5 answers

2

Android already has a layout that makes your children overlap, is FrameLayout , replace RelativeLayout with it like this:

<FrameLayout
   ... // width, height e tudo do RelativeLayout aqui>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#00008B"/>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#008B45"/>

</LinearLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:elevation="@dimen/activity_vertical_margin"
    android:text="CHAPÉU SELETOR"
    android:textColor="#FFFFFF"
    android:textSize="40sp"
    android:gravity="center_vertical"
    android:layout_gravity="center"
    android:id="@+id/textView"/>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Testar"
    android:textSize="40sp"
    android:id="@+id/buttonStart"
    android:background="#FFFFFF"
    android:layout_gravity="center" />

</FrameLayout>

With this Layout the elements will already overlap. Any questions just comment.

    
24.06.2016 / 14:25
1

Try it out like this, it might work !!

If it does not work, tell me to try another way

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

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:elevation="@dimen/activity_vertical_margin"
            android:text="CHAPÉU SELETOR"
            android:textColor="#FFFFFF"
            android:textSize="40sp"
            android:gravity="center_vertical"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/textView"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Testar"
            android:textSize="40sp"
            android:id="@+id/buttonStart"
            android:background="#FFFFFF"
            android:layout_below="@+id/textView"
            android:layout_centerHorizontal="true" />
    </FrameLayout>
    
24.06.2016 / 11:49
0

I'm sorry, I solved the case by changing the order, putting the textView and Button at the end of RelativeLayout, I had posted the code this way, but in my project I do not know why I had undone this put the textView and the Button at the beginning of the code. Now everything went well, thank you all for the answers, thank you

    
25.06.2016 / 19:31
0

Invert the order of the code.

On Android the order of factors changes the product :) If not, I've changed the emulator and see if it works.

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.uriel.aaa.MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:elevation="@dimen/activity_vertical_margin"
        android:gravity="center_vertical"
        android:text="aaa"
        android:textColor="#FFFFFF"
        android:textSize="40sp" />

    <Button
        android:id="@+id/buttonStart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:background="#FFFFFF"
        android:text="Testar"
        android:textSize="40sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:orientation="horizontal">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00008B"
            android:orientation="horizontal" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#008B45"
            android:orientation="horizontal" />
    </LinearLayout>

</RelativeLayout>
    
04.11.2017 / 22:22
0

Hello. The contraintLayout is what I use most, and there, the order of the factors can overlap yes.

        <RadioButton
            android:id="@+id/radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:layout_weight="1"
            android:background="@color/fbutton_color_clouds"
            android:checked="false"
            android:text="Bloco 40 cm"
            android:textAlignment="viewStart"
            android:textColor="@color/fbutton_color_wet_asphalt"
            tools:layout_editor_absoluteX="152dp"
            tools:layout_editor_absoluteY="484dp" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@color/fbutton_color_clouds"
            android:checked="false"
            android:duplicateParentState="false"
            android:text="Bloco 33 cm"
            android:textColor="@color/fbutton_color_wet_asphalt"
            tools:layout_editor_absoluteX="27dp"
            tools:layout_editor_absoluteY="484dp" />

    </RadioGroup>



    <TextView
        android:id="@+id/textView5"
        android:layout_width="185dp"
        android:layout_height="103dp"
        android:layout_alignParentTop="true"
        android:layout_weight="1"
        android:text="Os blocos de EPS podem ter  40cm ou 33cm de largura. Escolha o que irá ser utilizado"
        android:textAlignment="center"
        android:textColor="@color/colorPrimary"
        android:textSize="14sp"
        app:layout_constraintTop_toTopOf="@+id/radioGroup2"
        tools:layout_editor_absoluteX="149dp" />

    
09.11.2017 / 14:03