One component on top of the other

Asked

Viewed 12,363 times

4

I’m in trouble that I do not think how to solve, I have an Activity as in the photo below, the problem is, that when I emulate the application, the Button and the textView go down the two colored Linearlayouts (blue and green).

PrintScreen do que está acontecendo

I would like to know how to assign a property to Button and textView, so that they are above the Layouts

Note: I didn’t want to put the Button and the textView inside the colored Layouts.

<?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>

  • 1

    Can share layout XML?

  • 1

    Talks Uriel, tries to put the Buttons after the layouts in XML, but as Professor Matthew said, you better send XML, Hugs.

  • oops, I put it there, I forgot, sorry

  • the main layout of Activity is Framelayout?

  • Did you put all the xml layout in the question? There is no Groupview that is "root" or "parent of all" as a Relativelayout, Linearlayout or Framelayout?

  • This is inside a relativeLayout, but when I copied and pasted did not appear sorry, on the print to see there in the tree

  • You could post the Activity Java code for this layout?

  • @Urielkindermann, I ran here and it normally appeared Textview and Button above the layout. Could you put the Activity code so we can try to figure out what’s going on?

Show 3 more comments

5 answers

3

The android already has a layout that makes your children overlap, is the FrameLayout, replace the RelativeLayout for his sake:

<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 that Layout the elements will already overlap. Any doubt just comment.

  • I believe that in his case the problem may be related to the Activity code, because I performed the tests with his layout and it worked

  • I also ran a test with exactly his layout and it worked. I don’t think the problem is in xml like @Vitorhenrique. Let’s wait for the Activity code.

  • It is also true that sometimes the problem is not always where we think kkk. But as only one side of the problem was shown I could only do that

1

Try it this way, it might work!!

If Funcina doesn’t tell me to try it 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>
  • 1

    You didn’t explain what you did, just put a code that doesn’t even make a difference to the question code it seems to have. Explain what you did, please...

  • forget to start <Framelayout I will edit my reply

  • 2

    forget one thing and it’s logo down votes :) I think for the next one just search a little, because it’s already been answered this question: http://stackoverflow.com/questions/29740456/overlay-floating-button-in-linear-layout http://stackoverflow.com/questions/29072946/how-do-i-create-overlay-button-in-my-android-layout

  • 1

    Francis, I don’t believe that you were denied because of an error in your code, because that someone would edit for you including. This only happened because you didn’t explain what you did and why you did it. You just paste the code as a response, it is necessary to generate understanding with your response...

  • Yes you are right, for the next explanation better, Ja I left 2 links to see all possible information on the subject and easy to understand!!

0

Reverse the order of the code.

In Android the order of the factors changes the product :) If not, I switched emulator and check 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>

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 don’t know why I had undone it put the textView and Button at the beginning of the code. Now it’s all worked out, thank you all for your answers, thank you very much

0

Hello. The contraintLayout is what I most use, 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" />

Browser other questions tagged

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