The import android. The content. The Context;
The import android. Content. Res. TypedArray;
The import android. Graphics. Canvas;
The import android. Graphics. Color;
The import android. Graphics. That LinearGradient;
The import android. Graphics. Paint;
The import android. Graphics. The Path;
The import android. Graphics. The Rect;
The import android. Graphics. Shader;
The import android. Util. AttributeSet;
The import android. View. The view;
The import androidx. The annotation. Nullable;
Public class ArcView extends the View {
Private int mWidth;
Private int mHeight;
Private int mArcHeight;//the height of circular arc
Private int mBgColor;//background color
Private int lgColor;//change the final color of
Private Paint mPaint;//brush
Private that LinearGradient that LinearGradient;
Private the Rect the Rect=new the Rect (0,0,0,0);//ordinary rectangular
Private Path Path=new Path ();//to draw surface
Public ArcView Context (Context) {
This (context, null);
}
Public ArcView (Context Context, @ Nullable AttributeSet attrs) {
This (context, attrs, 0);
}
Public ArcView (Context Context, @ Nullable AttributeSet attrs, int defStyleAttr) {
Super (context, attrs, defStyleAttr);
TypedArray TypedArray=context. ObtainStyledAttributes (attrs, R.s tyleable. ArcView);
MArcHeight=typedArray. GetDimensionPixelSize (R.s tyleable. ArcView_arcHeight, 0);
MBgColor=typedArray. GetColor (R.s tyleable ArcView_bgColor, Color. ParseColor (" # FFFFFF "));
LgColor=typedArray. GetColor (R.s tyleable ArcView_lgColor, mBgColor);
MPaint=new Paint ();
MPaint. SetAntiAlias (true);
TypedArray. Recycle ();
}
@ Override
Protected void onSizeChanged (int w, int h, int oldw, int oldh) {
Super. OnSizeChanged (w, h, oldw, oldh);
//the d (" - ", "onSizeChanged");
That linearGradient=new that linearGradient (0, 0, getMeasuredWidth () and 0,
MBgColor lgColor, Shader. TileMode. CLAMP
);
MPaint. SetShader (that linearGradient);
}
@ Override
Protected void ontouch (Canvas, Canvas) {
Super. Ontouch (canvas);
//set to fill the
MPaint. SetStyle (Paint. Style. The FILL);
MPaint. SetColor (mBgColor);
//draw a rectangle
The rect. Set (0, 0, mWidth, mHeight - mArcHeight);
Canvas. DrawRect (the rect, mPaint);
//draw the path
Path. The moveTo (0, mHeight - mArcHeight);
Path. QuadTo (mWidth & gt;> 1, mHeight, mWidth, mHeight - mArcHeight);
Canvas. DrawPath (path, mPaint);
}
@ Override
Protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
Super. OnMeasure (widthMeasureSpec, heightMeasureSpec);
Int widthSize=MeasureSpec. GetSize (widthMeasureSpec);
Int widthMode=MeasureSpec. GetMode (widthMeasureSpec);
Int heightSize=MeasureSpec. GetSize (heightMeasureSpec);
Int heightMode=MeasureSpec. GetMode (heightMeasureSpec);
If (widthMode==MeasureSpec. EXACTLY) {
MWidth=widthSize;
}
If (heightMode==MeasureSpec. EXACTLY) {
MHeight=heightSize;
}
SetMeasuredDimension (mWidth, mHeight);
}
}
The above code implements a custom view, but can't add the button in the following layout
Android: layout_height="195 dp"
App: arcHeight="23 dp"
App: lgColor="@ color/white
"App: bgColor="@ color/white & gt;"
Excuse me, how can you add in the custom view button, and the pictures?