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 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.You should use LinearLayout or RelativeLayout in FrameLayout . Like this way
As the official android documantation points out:
It's better if you put your
Button
andTextview
in aRelativeLayout
inside theFrameLayout
like:This answer
Apperently android:stateListAnimator="@null" works only for API = 21 or higher, So for those who target API<21 use this, it worked for me :D
Put in your
Button
insideFrameLayout
In the Android 5.0 (API 21) and above, you must add android:elevation into the view.