Issue
My problem - In my layout when a button is pressed the view that is above is getting hidden.
Let's take a simple layout for example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr"
android:orientation="vertical">
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/button"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="This is view"
android:textColor="#ffffff"
android:background="#000000"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/button" />
This layout will look like this (the black view will be above the 2 buttons):
My problem is that when I click one of the buttons that are below the black view it will get hidden:
Is there any way to keep the button animation but prevent the situation that the black view is getting hidden by the button click event?
Solution
The problem is with the default animation that Android uses to animate the buttons. After clicking a button by default its Z property (this is the elevation of the button) is increased to allow for the cool shadow effects. You can check more on elevation and translationZ in this article:
In order to fix your problem you can do the following:
In your XML file use android:stateListAnimator="@null"
on the button that you want to stay in background. There is a very good post on this issue which you can also check:
Android 5.0 android:elevation Works for View, but not Button?
Answered By - Yordan Lyutskanov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.