I'm learning android. I want to use in my application such a graphic view, as below in the image. Googled for a long time, but found nothing (maybe, I was looking for it in a wrong or wrong way).

Question: How can ImageButton and TextView fit into a circle? If the circle is a separate element of the graphical interface, then how can the elements be superimposed on each other?

ui-component

    1 answer 1

    Elements can overlap each other if the parent view group component is not inherited from LinearLayout , i.e. FrameLayout , RelativeLayout , CoordinatorLayout , ConstraintLayout .

    And you can draw a circle on the background through Drawable:

     <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@color/red"/> <size android:width="30dp" android:height="30dp"/> </shape> 

    And then set the parameter of the parent component android:src="@drawable/название_вашего_файла_с_кругом"

    Very intelligibly explained in the lessons here.

    • it is better to set the background to the container that contains the widgets. and not a forward image to some component. whoever he is - pavlofff
    • The background can be stretched, so this is not the best idea - zTrap
    • Thank you very much, I will try! - Alexander
    • @ Alexander could not accept the answer if he helped you. Here it is assumed: "What to do with the answers to my question?" - zTrap