public?class?ViewPagerTittleView?extends?LinearLayout?{
????private?static?final?String?TAG?=?"View";
????private?Paint?mPaint;
????private?Path?mPath;
????private?int?mWidth;
????private?int?mHeight;
????private?static?final?float?WIDTH_RADIO?=?1/6f;
????private?int?mInitTransX;
????private?int?mTransX;
????public?ViewPagerTittleView(Context?context)?{
????????this(context,null);
????}
????public?ViewPagerTittleView(Context?context,?AttributeSet?attrs)?{
????????super(context,?attrs);
????????mPaint?=?new?Paint();
????????mPaint.setStyle(Paint.Style.FILL);
????????mPaint.setAntiAlias(true);
????????mPaint.setColor(Color.parseColor("#ffffff"));
????????Log.d("View",?"ViewPagerTittleView:?***********");
????}
????@Override
????protected?void?dispatchDraw(Canvas?canvas)?{
????????canvas.save();
????????canvas.translate(mInitTransX+mTransX,getHeight());
????????canvas.drawPath(mPath,mPaint);
????????canvas.restore();
????????Log.d(TAG?,?"dispatchDraw:?*****");
????????super.dispatchDraw(canvas);
????}
????@Override
????protected?void?onSizeChanged(int?w,?int?h,?int?oldw,?int?oldh)?{
????????super.onSizeChanged(w,?h,?oldw,?oldh);
????????mWidth?=?(int)?(w/3*WIDTH_RADIO);
????????mHeight?=?mWidth/2;
????????mInitTransX?=?w/3/2-mWidth/2;
????????initTriangle();
????????Log.d(TAG,?"onSizeChanged:?********");
????????Log.d(TAG,?"onSizeChanged:?mWidth?=?"+mWidth+"???mInitTranslationX?=?"+mInitTransX+
????????????????"??mHeight?=?"+mHeight);
????}
????/**
?????*?初始化三角形
?????*/
????private?void?initTriangle()?{
????????mPath?=?new?Path();
????????mPath.moveTo(0,0);
????????mPath.lineTo(mWidth,0);
????????mPath.lineTo(mWidth/2,-mHeight);
????????mPath.close();
????????Log.d("View",?"initTriangle:***************?");
????}
}
2017-01-21
我的代碼能顯示,你可以對(duì)比下,主要注意下位置是不是設(shè)置得有問題,超出顯示區(qū)域的話是看不到的,還有顏色如果一樣也是看不出來的
2016-05-17
我的也出不來效果
2016-05-09
那你能畫出什么,貌似這段沒有問題~