Android涓娇鐢–anvas鍜孭aint缁樺埗涓€涓畨鍗撴満鍣ㄤ汉
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android涓娇鐢–anvas鍜孭aint缁樺埗涓€涓畨鍗撴満鍣ㄤ汉相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/xtend' title='xtend'>xtend 鐢靛瓙 image 娣诲姞 ref state contex idg addview
鍦烘櫙
鍦ˋndroid涓敾绗斾娇鐢≒aint绫伙紝鐢诲竷浣跨敤Canvas绫绘潵琛ㄧず銆?/p>
缁樺浘鐨勫熀鏈楠?/p>
棣栧厛缂栧啓涓€涓户鎵胯嚜View鐨勮嚜瀹氫箟View绫伙紝鐒跺悗閲嶅啓鍏秓nDraw鏂规硶锛屾渶鍚庢妸鑷畾涔夌殑view娣诲姞鍒癮ctvity涓€?/p>
鏁堟灉
https://blog.csdn.net/badao_liumang_qizhi
鍏虫敞鍏紬鍙?
闇搁亾鐨勭▼搴忕尶
鑾峰彇缂栫▼鐩稿叧鐢靛瓙涔︺€佹暀绋嬫帹閫佷笌鍏嶈垂涓嬭浇銆?/p>
瀹炵幇
棣栧厛鍦ㄨ鏄剧ず鐨凙ctivity鐨勫竷灞€鏂囦欢涓慨鏀逛负FrameLayout骞舵坊鍔犱竴涓猧d銆?
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/frameLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".RobitActivity"> </FrameLayout>
鐒跺悗鍦ˋCtivity涓柊寤鸿嚜瀹氫箟View绫伙紝杩欓噷鏄疢yView浣垮叾缁ф壙View绫诲苟缂栧啓涓€涓甫涓€涓弬鏁扮殑鏋勯€犳柟娉曞拰閲嶅啓onDraw鏂规硶銆?/p>
鍦ㄩ噸鍐欑殑onDraw鏂规硶涓柊寤虹敾绗斿苟璁剧疆涓€浜涘睘鎬э紝鐒跺悗浣跨敤鐢荤瑪鍦ㄧ敾甯冧笂鎸囧畾鐨勪綅缃粯鍒跺浘褰€?/p>
package com.badao.alarmmanager; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.os.Bundle; import android.view.View; import android.widget.FrameLayout; public class RobitActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_robit); FrameLayout frameLayout= (FrameLayout) findViewById(R.id.frameLayout); //鑾峰彇甯у竷灞€绠$悊鍣?/span> frameLayout.addView(new MyView(this)); //灏嗚嚜瀹氫箟瑙嗗浘鐨勫唴閮ㄧ被娣诲姞鍒板竷灞€绠$悊鍣ㄤ腑 } private class MyView extends View { public MyView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint=new Paint(); //榛樿璁剧疆鍒涘缓涓€涓敾绗?/span> paint.setAntiAlias(true); //浣跨敤鎶楅敮榻垮姛鑳?/span> paint.setColor(0xFFA4C739); //璁剧疆鐢荤瑪鐨勯鑹蹭负缁胯壊 //缁樺埗鏈哄櫒浜虹殑澶?/span> RectF rectf_head=new RectF(10, 10, 100, 100); rectf_head.offset(90, 20); canvas.drawArc(rectf_head, -10, -160, false, paint); //缁樺埗寮? //缁樺埗鐪肩潧 paint.setColor(Color.WHITE); //璁剧疆鐢荤瑪鐨勯鑹蹭负鐧借壊 canvas.drawCircle(125, 53, 4, paint); //缁樺埗鍦?/span> canvas.drawCircle(165, 53, 4, paint); //缁樺埗鍦?/span> paint.setColor(0xFFA4C739); //璁剧疆鐢荤瑪鐨勯鑹蹭负缁胯壊 //缁樺埗澶╃嚎 paint.setStrokeWidth(2); //璁剧疆绗旇Е鐨勫搴?/span> canvas.drawLine(110, 15, 125, 35, paint); //缁樺埗绾?/span> canvas.drawLine(180, 15, 165, 35, paint); //缁樺埗绾? //缁樺埗韬綋 canvas.drawRect(100, 75, 190, 150, paint); //缁樺埗鐭╁舰 RectF rectf_body=new RectF(100,140,190,160); canvas.drawRoundRect(rectf_body, 10, 10, paint); //缁樺埗鍦嗚鐭╁舰 //缁樺埗鑳宠唺 RectF rectf_arm=new RectF(75,75,95,140); canvas.drawRoundRect(rectf_arm, 10, 10, paint); //缁樺埗宸︿晶鐨勮兂鑶?/span> rectf_arm.offset(120, 0); //璁剧疆鍦╔杞翠笂鍋忕Щ120鍍忕礌 canvas.drawRoundRect(rectf_arm, 10, 10, paint); //缁樺埗鍙充晶鐨勮兂鑶? //缁樺埗鑵?/span> RectF rectf_leg=new RectF(115,150,135,200); canvas.drawRoundRect(rectf_leg, 10, 10, paint); //缁樺埗宸︿晶鐨勮吙 rectf_leg.offset(40, 0); //璁剧疆鍦╔杞翠笂鍋忕Щ40鍍忕礌 canvas.drawRoundRect(rectf_leg, 10, 10, paint); //缁樺埗鍙充晶鐨勮吙 } } }
以上是关于Android涓娇鐢–anvas鍜孭aint缁樺埗涓€涓畨鍗撴満鍣ㄤ汉的主要内容,如果未能解决你的问题,请参考以下文章
Bash 涓娇鐢ㄦ帶鍒惰繍绠楃杩炴帴鍛戒护 | Linux 涓浗
涓€瀵逛竴鍏宠仈鏌ヨ鏃朵娇鐢╮elation杩炶疮鎿嶄綔鏌ヨ鍚庯紝璋冪敤getLastSql()鏂规硶杈撳嚭鐨剆ql璇彞
Windows Presentation Foundation(WPF)涓殑鏁版嵁缁戝畾锛堜娇鐢╔mlDataProvider浣滄帶浠剁粦瀹氾級