I have FrameLayout like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="changeColor" android:text="new button"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="some text"/> </FrameLayout>
The problem is that the button is displayed on top while FrameLayout class overview tells us this: "Child views are drawn in a stack, with the most recently added child on top".
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.
RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets. TableLayout : is a view that groups its child views into rows and columns. FrameLayout : is a placeholder on screen that is used to display a single ...
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
Show activity on this post. A framelayout, Relative View and a few others represents a view in android and is extended from viewgroup. A Fragment is a an an Object that is used to represent a portion of a user interface and is usually hosted in an activity. A fragment has a viewgroup which you can assign an XML layout.
This answer
Buttons in Lollipop and higher have a default elevation to them which causes them to always draw on top. You can change this by overriding the default StateListAnimator.
Try putting this into your button XML:
android:stateListAnimator="@null"
The FrameLayout should now cover the button.
In the Android 5.0 (API 21) and above, you must add android:elevation into the view.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="changeColor" android:text="new button"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="some text" android:elevation="3dp"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With