1, you need to add this kind of code to the constructors of your custom view which must extend ViewGroup, and the parameter attachToRoot must be true. LayoutInflater.from(context).inflate(R.layout.yourLayout, this, true); 2,If you want to add your cu
TextView android:gravity="center" //文字对其方式 top bottom left right center android:textColor="#ffffff"//颜色 android:textSize="24sp" //字体 android:layout_width="wrap_content"//布局文字宽填充 android:layout_height="wrap_cont