├── .gitattributes ├── .gitignore ├── README.md └── TestDraw ├── .classpath ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.ui.prefs ├── AndroidManifest.xml ├── gen └── com │ └── example │ └── testdraw │ ├── BuildConfig.java │ └── R.java ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── layout │ ├── activity_course_testcourse_report.xml │ └── test_rect.xml ├── menu │ └── main.xml ├── values-sw600dp │ └── dimens.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── src └── com └── example └── testdraw ├── CustomCircle.java ├── CustomRect.java ├── CustomTrigon.java ├── PointBean.java └── TestCourseReportActivity.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must end with two \r 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Android的Graphics类绘制图形 (Canvas Paint Path) 2 | #(下面有效果图) 3 | 4 | 5 | English Description 6 | 7 | This Demo is through the Canvas on the Graphics class Adnroid, Paint, the Path to map the instance of project, for your reference 8 | 9 | BaseAnimation QQ group:149581646 10 | 11 | Author's blog: http://blog.csdn.net/duguang77 12 | 13 | 14 | 15 | 16 | 中文说明 17 | 18 | 这个Demo是通过Adnroid的Graphics类中的Canvas,Paint,Path绘制出的实例工程,供大家参考 19 | 20 | BaseAnimation QQ群:149581646 21 | 22 | 作者博客:http://blog.csdn.net/duguang77 23 | 24 | 25 | 26 | ==== 27 | 28 | 29 | # ScreenShot 30 | 31 | ![Image][1] 32 | . 33 | ![Image][2] 34 | . 35 | ![Image][3] 36 | 37 | ![Image][4] 38 | 39 | 40 | 41 | [1]: http://img.blog.csdn.net/20141106215620406 42 | [2]: http://img.blog.csdn.net/20141107124210406 43 | [3]: http://img.blog.csdn.net/20141106220033956 44 | [4]: http://img.blog.csdn.net/20141106220153781 45 | 46 | 这样拆分出来的图,大家就应该知道这张图示怎么画的吧! 47 | 我们来细讲一下,圆心点坐标我们通过 48 | protected void onDraw(Canvas canvas) { 49 | super.onDraw(canvas); 50 | mWidth = canvas.getWidth(); 51 | mHeight = canvas.getHeight(); 52 | mCenterX = mWidth/2; 53 | mCenterY = mHeight/4; 54 | } 55 | 56 | 继承的View类 OnDraw()方法中的Canvas获取出屏幕一半宽,1/4高的点的位置,这就是上图中的O点坐标,而柱状体我们也是通过自己给的坐标点画出的,所以这两个点都是已知的。 57 | 58 | 我们最重要的是控制好过圆心,画出三角形, 59 | 我们通过之前了解到通过Canvas+Path+Paint组合API可以画出三角形,但是我们并不知道点P和P'的坐标位置, 60 | 61 | //开始画三角形 62 | Path path = new Path();// 三角形 63 | 64 | 65 | path.moveTo((float)(x2), (float)(y2));//P点坐标 66 | path.lineTo((float)(mPointB.x), (float)(mPointB.y));//圆心点坐标 67 | path.lineTo((float)x1, (float)y1);//P'点坐标 68 | path.close();//闭合画笔路径 69 | canvas.drawPath(path, paint);//开始画 70 | 71 | 通过简化图,我们可以看出,其实就是一个数学问题,通过点O坐标和点H坐标,OP'和OP边长是自己给定的定值所以也是已知的,OH边长已知,PH和P'H通过勾三股四算出可得,有了这些参数我们就可以组成一个二元一次方程组来算出P和P'坐标如下所示 72 | -------------------------------------------------------------------------------- /TestDraw/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TestDraw/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TestDraw 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /TestDraw/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/com/example/testdraw/CustomTrigon.java=UTF-8 3 | -------------------------------------------------------------------------------- /TestDraw/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /TestDraw/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.ui.javadoc=false 3 | org.eclipse.jdt.ui.text.custom_code_templates= 4 | -------------------------------------------------------------------------------- /TestDraw/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /TestDraw/gen/com/example/testdraw/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.example.testdraw; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /TestDraw/gen/com/example/testdraw/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package com.example.testdraw; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class color { 14 | public static final int bar=0x7f04002b; 15 | public static final int bg_ty_gra_bestdeep=0x7f040024; 16 | public static final int bg_ty_gray=0x7f040026; 17 | public static final int bg_ty_gray_deep=0x7f040025; 18 | public static final int bg_ty_gray_deep2=0x7f040027; 19 | public static final int bg_ty_text_deep=0x7f040028; 20 | public static final int bg_ty_text_deep2=0x7f040029; 21 | /** 预约体验课 22 | */ 23 | public static final int bg_ty_yellow_deep=0x7f040023; 24 | /** 黑色 25 | */ 26 | public static final int black=0x7f04001e; 27 | public static final int btn_bg_deep_yellow=0x7f040021; 28 | public static final int btn_bg_white=0x7f040022; 29 | /** Button相关 30 | */ 31 | public static final int btn_bg_yellow=0x7f040020; 32 | public static final int btn_classroom_color01=0x7f04000b; 33 | public static final int btn_classroom_color02=0x7f04000c; 34 | public static final int btn_close_normal=0x7f040010; 35 | public static final int btn_close_press=0x7f04000f; 36 | public static final int btn_press_color=0x7f040009; 37 | public static final int btn_send_msg_normal=0x7f04000e; 38 | public static final int btn_send_msg_press=0x7f04000d; 39 | public static final int btn_unpress_color=0x7f04000a; 40 | /** PDF相关 41 | */ 42 | public static final int canvas=0x7f04002a; 43 | public static final int cm_title_tv_gray=0x7f040003; 44 | public static final int cm_title_tv_yellow=0x7f040002; 45 | /** 体验课相关的颜色 start 46 | */ 47 | public static final int cril=0x7f04002c; 48 | public static final int dialog_bg=0x7f040007; 49 | public static final int divider_color=0x7f040005; 50 | public static final int font_color_b=0x7f040001; 51 | public static final int font_color_y=0x7f040000; 52 | public static final int main_brown_color=0x7f040015; 53 | /** 主灰背景色 54 | */ 55 | public static final int main_graybg_color=0x7f04001b; 56 | /** 间隙线color 57 | */ 58 | public static final int main_line_color=0x7f04001a; 59 | /** 字体主色 60 | */ 61 | public static final int main_word_color=0x7f040011; 62 | public static final int main_word_lightGray=0x7f040013; 63 | public static final int main_word_lightRed=0x7f040014; 64 | public static final int main_wordgray_color=0x7f040012; 65 | public static final int main_wordyellow_color=0x7f040017; 66 | public static final int main_yellow_color=0x7f040016; 67 | public static final int msg_color=0x7f040006; 68 | public static final int rect_cril_leve1=0x7f04002d; 69 | public static final int rect_cril_leve2=0x7f04002e; 70 | public static final int rect_cril_leve3=0x7f04002f; 71 | public static final int rect_cril_leve4=0x7f040030; 72 | public static final int rect_cril_leve5=0x7f040031; 73 | public static final int rect_cril_leve6=0x7f040032; 74 | public static final int tabbar_color=0x7f04001c; 75 | /** Dialog相关 76 | */ 77 | public static final int text_color=0x7f040004; 78 | public static final int text_color_hint=0x7f04001f; 79 | public static final int text_hide=0x7f040034; 80 | public static final int text_level=0x7f040033; 81 | public static final int title_bg=0x7f040008; 82 | public static final int view_backgroud=0x7f040035; 83 | /** 白色 84 | */ 85 | public static final int white=0x7f04001d; 86 | public static final int word_text=0x7f040019; 87 | public static final int word_text_hide_delete=0x7f040018; 88 | } 89 | public static final class dimen { 90 | /** Default screen margins, per the Android Design guidelines. 91 | 92 | Customize dimensions originally defined in res/values/dimens.xml (such as 93 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. 94 | 95 | */ 96 | public static final int activity_horizontal_margin=0x7f050000; 97 | public static final int activity_vertical_margin=0x7f050001; 98 | } 99 | public static final class drawable { 100 | public static final int ic_launcher=0x7f020000; 101 | } 102 | public static final class id { 103 | public static final int action_settings=0x7f090007; 104 | public static final int cus_rect=0x7f090001; 105 | public static final int fl_mian=0x7f090000; 106 | public static final int tv_hide=0x7f090003; 107 | public static final int tv_hide_one=0x7f090002; 108 | public static final int tv_hide_two=0x7f090006; 109 | public static final int tv_level=0x7f090004; 110 | public static final int view_line=0x7f090005; 111 | } 112 | public static final class layout { 113 | public static final int activity_course_testcourse_report=0x7f030000; 114 | public static final int test_rect=0x7f030001; 115 | } 116 | public static final class menu { 117 | public static final int main=0x7f080000; 118 | } 119 | public static final class string { 120 | public static final int action_settings=0x7f060001; 121 | public static final int app_name=0x7f060000; 122 | public static final int hello_world=0x7f060002; 123 | } 124 | public static final class style { 125 | /** 126 | Base application theme, dependent on API level. This theme is replaced 127 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 128 | 129 | 130 | Theme customizations available in newer API levels can go in 131 | res/values-vXX/styles.xml, while customizations related to 132 | backward-compatibility can go here. 133 | 134 | 135 | Base application theme for API 11+. This theme completely replaces 136 | AppBaseTheme from res/values/styles.xml on API 11+ devices. 137 | 138 | API 11 theme customizations can go here. 139 | 140 | Base application theme for API 14+. This theme completely replaces 141 | AppBaseTheme from BOTH res/values/styles.xml and 142 | res/values-v11/styles.xml on API 14+ devices. 143 | 144 | API 14 theme customizations can go here. 145 | */ 146 | public static final int AppBaseTheme=0x7f070000; 147 | /** Application theme. 148 | All customizations that are NOT specific to a particular API-level can go here. 149 | */ 150 | public static final int AppTheme=0x7f070001; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /TestDraw/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/ic_launcher-web.png -------------------------------------------------------------------------------- /TestDraw/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/libs/android-support-v4.jar -------------------------------------------------------------------------------- /TestDraw/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /TestDraw/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /TestDraw/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /TestDraw/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /TestDraw/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /TestDraw/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /TestDraw/res/layout/activity_course_testcourse_report.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 16 | 17 | 23 | 24 | 25 | 32 | 33 | 40 | 41 | 47 | 48 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /TestDraw/res/layout/test_rect.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /TestDraw/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /TestDraw/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TestDraw/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /TestDraw/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TestDraw/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /TestDraw/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ff7d00 5 | #515151 6 | #FFA656 7 | #B3A19D 8 | 9 | 10 | #FFFFFF 11 | #11000000 12 | #FFFFFFFF 13 | #FFFFFFFF 14 | #22FFFFFF 15 | 16 | 17 | #FFa5281b 18 | #FFc0392b 19 | 20 | 21 | #FFFF7d00 22 | #88FF7d00 23 | 24 | #F2F2F2 25 | #FFFAFAFA 26 | 27 | #9D9D9D 28 | #d0d0d0 29 | 30 | 31 | #333333 32 | #828282 33 | #c5c5c5 34 | #ff6262 35 | 36 | #cccdcf 37 | #ff8121 38 | #ff8200 39 | #9f9f9f 40 | #a9a9a9 41 | 42 | 43 | #cccdcf 44 | 45 | #e3e4e6 46 | #F8F8F8 47 | 48 | 49 | 50 | #FFFFFF 51 | 52 | #000000 53 | #c5b295 54 | 55 | 56 | #FFCD00 57 | #FE9900 58 | #FFFFFF 59 | 60 | 61 | #FF8200 62 | #474747 63 | #e3e4e6 64 | #f7f7f7 65 | #c5c5c5 66 | #999999 67 | #ADADAD 68 | 69 | 70 | 71 | #FF404040 72 | #C0202020 73 | 74 | 75 | 76 | 77 | #09bdba 78 | #09bdba 79 | #00cebe 80 | #4abf71 81 | #ADBA36 82 | #D9A400 83 | #FF9E01 84 | #76c8bc 85 | #323232 86 | #e6e6e6 87 | 88 | 89 | -------------------------------------------------------------------------------- /TestDraw/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /TestDraw/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TestDraw 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /TestDraw/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /TestDraw/src/com/example/testdraw/CustomCircle.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/src/com/example/testdraw/CustomCircle.java -------------------------------------------------------------------------------- /TestDraw/src/com/example/testdraw/CustomRect.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/src/com/example/testdraw/CustomRect.java -------------------------------------------------------------------------------- /TestDraw/src/com/example/testdraw/CustomTrigon.java: -------------------------------------------------------------------------------- 1 | package com.example.testdraw; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Paint.Style; 8 | import android.graphics.Path; 9 | import android.util.AttributeSet; 10 | import android.util.Log; 11 | import android.view.View; 12 | 13 | /** 14 | * 通过柱状体顶部中心点坐标和圆心点坐标,画出过圆心的三角形 15 | * @author DuGuang 16 | * blog地址:http://blog.csdn.net/duguang77 17 | */ 18 | public class CustomTrigon extends View { 19 | 20 | PointBean mPointA; //柱状体顶部中心坐标 21 | PointBean mPointB = new PointBean(760, 400); //初始化时,假设的一个圆心点坐标 22 | 23 | private float mCenterX; //圆心点坐标X 24 | private float mCenterY; //圆心点坐标Y 25 | private int mWidth; //画布的宽 == 手机屏幕的宽 26 | private int mHeight;//画布的高 == 手机屏幕的高 - ActionBar - 顶部title 27 | 28 | public CustomTrigon(Context context) { 29 | super(context); 30 | } 31 | 32 | public CustomTrigon(Context context, AttributeSet attrs, int defStyle) { 33 | super(context, attrs, defStyle); 34 | } 35 | 36 | public CustomTrigon(Context context, AttributeSet attrs) { 37 | super(context, attrs); 38 | } 39 | 40 | @SuppressLint("DrawAllocation") 41 | @Override 42 | protected void onDraw(Canvas canvas) { 43 | super.onDraw(canvas); 44 | mWidth = canvas.getWidth(); 45 | mHeight = canvas.getHeight(); 46 | mCenterX = mWidth/2; 47 | mCenterY = mHeight/4; 48 | 49 | mPointA = new PointBean((int)mCenterX, (int)mCenterY); 50 | 51 | Paint paint = new Paint(); 52 | paint.setAntiAlias(true); 53 | paint.setStyle(Style.FILL); 54 | paint.setStrokeWidth(30f); 55 | paint.setDither(true); 56 | paint.setColor(getResources().getColor(R.color.cril)); 57 | 58 | 59 | // cosA=(b²+c²-a²)/(2bc) 60 | // cosB=(a²+c²-b²)/(2ac) 61 | // cosC=(a²+b²-c²)/(2ab) 62 | // 63 | // 则由反余弦函数的定义可知: 64 | // A=arccos(cosA)=arccos((b²+c²-a²)/(2bc)); 65 | // B=arccos(cosB)=arccos((a²+c²-b²)/(2ac)); 66 | // C=arccos(cosC)=arccos((a²+b²-c²)/(2ab)); 67 | double mLineB = 581d; 68 | double mLineC = 584d; 69 | double mLineA = 50d; 70 | 71 | double mAcosA = Math 72 | .acos(((mLineB * mLineB) + (mLineC * mLineC) - (mLineA * mLineA)) 73 | / (2d * mLineB * mLineC)); 74 | 75 | double mAcosB = Math 76 | .acos(((mLineA * mLineA) + (mLineC * mLineC) - (mLineB * mLineB)) 77 | / (2d * mLineA * mLineC)); 78 | 79 | double mAcosC = Math 80 | .acos(((mLineA * mLineA) + (mLineB * mLineB) - (mLineC * mLineC)) 81 | / (2d * mLineA * mLineB)); 82 | 83 | 84 | getDot2(paint, canvas); 85 | 86 | } 87 | 88 | public void getDot2(Paint paint, Canvas canvas) { 89 | //下面公式通过圆心点坐标和柱状体顶部中心点坐标,通过二元一次方程组计算出其余两个三角形的坐标点位置 90 | // x=x1-a*sin{arctan[(y2-y1)/(x2-x1)]} 91 | // y=y1+a*cos{arctan[(y2-y1)/(x2-x1)]} 92 | 93 | 94 | //求出坐标点P 95 | double x1 = mPointA.x - 50 * Math.sin(Math.atan((mPointB.y - mPointA.y) / (mPointB.x - mPointA.x))); 96 | double y1 = mPointA.y + 50 * Math.cos(Math.atan((mPointB.y - mPointA.y) / (mPointB.x - mPointA.x))); 97 | 98 | //求出坐标点P' 99 | double x2 = mPointA.x + 50 * Math.sin(Math.atan((mPointB.y - mPointA.y) / (mPointB.x - mPointA.x))); 100 | double y2 = mPointA.y - 50 * Math.cos(Math.atan((mPointB.y - mPointA.y) / (mPointB.x - mPointA.x))); 101 | 102 | 103 | Log.i("dg", "x >>> " + x1 + " y >>> " + y1); 104 | 105 | //开始画三角形 106 | Path path = new Path();// 三角形 107 | 108 | 109 | path.moveTo((float)(x2), (float)(y2));//P点坐标 110 | path.lineTo((float)(mPointB.x), (float)(mPointB.y));//圆心点坐标 111 | path.lineTo((float)x1, (float)y1);//P'点坐标 112 | path.close();//闭合画笔路径 113 | canvas.drawPath(path, paint);//开始画 114 | 115 | } 116 | 117 | /** 118 | * 通过不同等级,塞入一个柱状体顶部中心点坐标 119 | * @param pointB 120 | */ 121 | public void setData(PointBean pointB){ 122 | mPointB = pointB; 123 | invalidate(); 124 | } 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /TestDraw/src/com/example/testdraw/PointBean.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/src/com/example/testdraw/PointBean.java -------------------------------------------------------------------------------- /TestDraw/src/com/example/testdraw/TestCourseReportActivity.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/z56402344/Android_Graphics_Instance_One/298e5c4b897d33ab49f3bd8df7dc67b59e0fdd79/TestDraw/src/com/example/testdraw/TestCourseReportActivity.java --------------------------------------------------------------------------------