0

Coming from Xcode, I'm really confused with Android Studio. I want to do such a simple thing as putting one view above another, but for some reason, the view I want to the front ends up in the back: enter image description here

imageButton should be in front of chapter1 but no matter how I arrange the hierarchy it still ends up in the back. Should I add imageButton as a subview to chapter1? Should I surround the items with a container? In Xcode, you just put one view on top of another. So much simpler, or am I missing something?

Community
  • 1
  • 1
tore
  • 619
  • 2
  • 9
  • 23
  • You should be able to set the `app:layout_constraintTop_toBottomOf` to set the top of `chapter1` to the bottom of `imageButton`. Alternatively, using the UI editor, when you highlight a component, there should be a little dot at each side that you can click+drag to any of the side of another component. – CodeMonkey Oct 03 '18 at 23:07
  • Thanks, but I think you're missing the point. I have already set the constraints as I want it to be. The problem is that imageButton is below chapter1. I want imageButton to be in front of chapter1... – tore Oct 04 '18 at 06:46
  • the way you proposed your question did not make that clear. – CodeMonkey Oct 04 '18 at 18:03

2 Answers2

1

OK, found an answer now: Android ConstraintLayout - Put one view on top of another view

For imageButton make sure that you add xml:

android:elevation="2dp"
tore
  • 619
  • 2
  • 9
  • 23
0

You can achieve that by using FrameLayout. In FrameLayout you can put views on top of each other with the last view under the hierarchy shown on top. To get ImageButton in front of Button view:

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

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
                
            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
          />
jedaDroid
  • 11
  • 1