-1

I need to put a TextView on top of a Button in a RelativeLayout, so i put the TextView before the Button, but it doesn't work

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
                android:id="@+id/textView"
                android:layout_width="20pt"
                android:layout_height="22pt"
                android:layout_gravity="start"
                android:layout_marginTop="4pt"
                android:background="@drawable/rounded_numbers"
                android:gravity="center"
                android:text="1" />
        <Button
                android:id="@+id/peso_but"
                android:layout_width="100pt"
                android:layout_height="20pt"
                android:layout_marginStart="17pt"
                android:layout_marginTop="5pt"
                android:background="@drawable/rounded_button"
                android:backgroundTint="#3399ff"
                android:fontFamily="@font/fira_sans_semibold"
                android:text="Button"
                android:textColor="#f5f5f5"
                android:textSize="8pt" />
</RelativeLayout>

As I know, putting one object before another should work, but it doesn't

I want something like this

Onik
  • 19,396
  • 14
  • 68
  • 91
Arfmann
  • 353
  • 1
  • 7
  • 18

4 Answers4

3

Try this you need to use FrameLayout for overlap views each other

   <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/peso_but"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#888"
        android:backgroundTint="#3399ff"
        android:text="Button"
        android:textColor="#f5f5f5"
        android:textSize="8pt" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/black"
        android:textColor="@color/white"
         android:gravity="center"
        android:elevation="100dp"
        android:text="1" />

</FrameLayout>
Bunny
  • 1,044
  • 12
  • 23
1

If you want TextView to overlap a Button replace your RelativeLayout with FrameLayout.

Nazarii Moshenskiy
  • 1,802
  • 2
  • 16
  • 35
0

add this to your button

android:layout_below="@+id/textView"
Mohammad Rbabah
  • 456
  • 2
  • 10
0

Try This Line in TextView

android:layout_abov="@+id/peso_but"
aasifghanchi
  • 102
  • 9