初探安卓画板
在java学习使用画板到现在貌似都快半年了,初探安卓的自定义组件使用到画板感觉非常不适用的样子。
在java使用的画板跟安卓的画板是有挺大的区别,下面记录一下学校安卓的画板的使用
在java当中,话矩形圆形都是空心的,而在安卓默认却是填满的
java当中使用Graphcs.draw-- 而在安卓却是吧画布当作参数放在后面……
package com.example.gaosi.blek; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Display; import android.view.Menu; import android.view.MenuItem; import android.widget.LinearLayout; public class Blek_MainActivity extends ActionBarActivity { /** * 程序的入口 * @param savedInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_blek__main); init(); } /** * 初始化 */ public void init(){ //获取界面的布局 LinearLayout linearLayout = (LinearLayout)this.findViewById(R.id.root); //创建drawView对象 DrawView drawView = new DrawView(this); //设置自定义界面的大小 drawView.setMinimumHeight(500); drawView.setMinimumWidth(300); //通知drawview组件重绘 drawView.invalidate(); //将drawview添加到应用的布局LinearLayout上面 linearLayout.addView(drawView); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_blek__main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
package com.example.gaosi.blek; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; /** * 话本 * Created by gaosi on 2015/4/28. */ public class DrawView extends View { /** * 构造方法,接收父类的参数context * @param context */ public DrawView(Context context){ super(context); } /** * onDraw重画方法 * 实现父类的onDraw 方法 * @param canvas */ protected void onDraw(Canvas canvas){ super.onDraw(canvas); /**画笔*/ Paint paint = new Paint(); //调用画图形花一些图形出来 drawVidios(canvas,paint); } /** * 画图形 * @param paint 画笔 */ public void drawVidios(Canvas canvas,Paint paint){ //设置画笔的颜色 paint.setColor(Color.BLACK); //设置画笔的锯齿状 paint.setAntiAlias(true); //设置画笔的主题,将画笔设置为空 paint.setStyle(Paint.Style.STROKE); canvas.drawLine(23,23,389,389,paint); //将画笔设置没有锯齿状 paint.setAntiAlias(false); //画矩形 canvas.drawRect(12,34,390,390,paint); } }
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28