0

I would prefer a text to appear in front of my image, but instead I cant see the text

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100dp"
    android:layout_height="50dp"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:gravity="center"
    app:cardCornerRadius="10dp"
    android:padding="8dp">

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

        <ImageView
            android:id="@+id/category_image_row"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:elevation="10dp"
            android:background="@color/black"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/txt_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:fontFamily="@font/cera_pro_bold"
            android:gravity="center"
            android:textColor="@color/white"
            android:textSize="18sp"
            tools:text="Shop" />
    </FrameLayout>

</androidx.cardview.widget.CardView>

Output

enter image description here

As we see here, I dont see the text above the image and I dont know why

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
SNM
  • 5,625
  • 9
  • 28
  • 77
  • Take a look at these answers. https://stackoverflow.com/questions/2629940/how-to-layer-views Your elevation puts the image above the text. – Tyler V May 16 '20 at 16:24
  • 4
    Does this answer your question? [How to layer views](https://stackoverflow.com/questions/2629940/how-to-layer-views) – Tyler V May 16 '20 at 16:24
  • but the color white is because I have a black background, I'm specting to see the text above the black image not below – SNM May 16 '20 at 16:25
  • The layer order is determined by the elevation in this case. Your black background is drawn on top of the white text, so you won't see it. – Tyler V May 16 '20 at 16:26
  • I have used framelayouts and is not working – SNM May 16 '20 at 16:26
  • @TylerV , can you elaborate an answer ? thanks – SNM May 16 '20 at 16:26
  • wow i did not see the elevation, my god, thanks ! – SNM May 16 '20 at 16:27
  • @CoffeeBreak, please remove the android:elevation="10dp" line.. you will see the text in white color. – Dhaval Shah May 16 '20 at 16:27
  • No, the solution in the answers there is to set elevation properly, or remove it (read all the answers, not just the top one, and try them before commenting that it doesn't work) - https://stackoverflow.com/a/41774058/9473786 – Tyler V May 16 '20 at 16:28

2 Answers2

0

Remove android:elevation="10dp" in ImageView tag

0

make sure they both have the same elevation, all items with lesser elevation will be "Beneath" them.

By the way, instead of a frame layout I would have done a constraint layout and set them up relatively as you want.

Idan Damri
  • 196
  • 10