I would like to make a similar button, but I do not quite understand how. I understand that you can make a clickable imageview, but at the same time you need to have a description below The same button

    2 answers 2

    Method 1:

    Create a container (LinearLayout) with a vertical orientation, put an ImageView and TextView in it. The listener hang on the container.

    Method 2:

    Take the opportunity to add a picture to any View to the left, right, top and / or bottom using the android:drawableTop attribute android:drawableTop (Left, Bottom, Right)

     <TextView android:layout_width="wrap_content" android:drawableTop="@drawable/ic_launcher" android:layout_height="wrap_content"> 

    The first way is better, because you will have more control over how the picture should look and be placed

    • And why did you add the LikeCount? id LikeCount? - P. Ilyin
    • @ P.Ilyin, copy-paste from Google and skipped) - YuriySPb
    • And when using the first method, the text on different screens of smartphones will not shift? - A.Schtolc
    • @ A.Schtolc, how can you set it up ... Put down the layout_gravity you need for the text and that's it ... - Juriy Spb
    • And if you use the second method, then the picture is not clickable? - A.Schtolc

    Using the drawableTop property of TextView can be a good solution:

     <TextView android:drawableTop="@drawable/some_drawable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="123" android:gravity="center" android:background="#ff55ff" /> 
    • Sorry if I ask a stupid question, but how can I make the picture itself clickable? - A.Schtolc