Search code examples
androidoverlapping

RelativeLayout's Last child doesn't display on top of other child


This is what I'm trying to achieve.

enter image description here

The actual result :

enter image description here

My XML is as below :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <Button
        android:id="@+id/question_button"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerInParent="true"
        android:textColor="@android:color/black"
        android:background="@drawable/oval_button"
        android:textSize="16sp"
        android:gravity="center"
        android:layout_marginTop="10dp"/>
    <TextView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:text="X"
        android:gravity="center"
        android:textColor="@android:color/white"
        android:background="@drawable/oval_grid_wrong"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

How do I bring the X TextView to the front?


Solution

  • try removing button default elevation in your xml

    <Button
    ...
    android:stateListAnimator="@null" 
    ....
    />