0

I have a Button which takes as input the text attribute of the button self. I need to embellish this button with an image that covers a part of the button. If I do it I expect to be still able to click the button surface, but is not the case, because the ImageView above the button is not clickable. I want that the ImageView or View( or whatever) is for aesthetics reasons on top of the button but that is completely ignored when I click on it, it would be like does not exist, taking as click the value of the button below, so that I can click all the surface of the Button comprehending the image on top taking only the input of the Button

<android.support.constraint.ConstraintLayout
android:id="@+id/ordinateur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toBottomOf="parent">

<Button
    android:layout_width="0dp"
    android:layout_width="wrap_content"
    android:id="@+id/numer_een"
    android:background="@drawable/le_click"
    android:layout_marginEnd="4dp"
    android:paddingBottom="24dp"
    android:text="1"
    android:onClick="ici"
    app:layout_constraintEnd_toStartOf="@+id/contraint1"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/constraint2">

</Button>
//here an image

</android.support.constraint.ConstraintLayout>
Drocchio
  • 383
  • 4
  • 21

2 Answers2

2

The solution was quite simple just I needed to add into the button a drawableBottom attribute as here where is suggested a drawableTop

Drocchio
  • 383
  • 4
  • 21
1

And using an ImageButton is not possible or what you want, I presume?

In that case might want to make your ImageView Clickable

android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"

and add a click listener to your ImageView, is that an idea?

((ImageView)findViewById(R.id.image)).setOnClickListener(this);
MartijndeM
  • 146
  • 1
  • 9
  • I thought already at that, but this is a workaround I do not like because I have a lot of buttons, and also since the button (below) takes as input the text( of the button itself), I should say into the Imageview listener on click that I need exactly the input of that button(that I determine via xml with android:text="string"). Is not possible that there is not an easier solution to put the image on top but considering still all the surface of the button below – Drocchio Apr 01 '19 at 12:04