文章插图
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubint progress=seekBar.getProgress();float count=progress/2f;paint.setStrokeWidth(count);}public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}});
触摸事件及其画线操作
iv.setOnTouchListener(new OnTouchListener() {public boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:startx=event.getX();starty=event.getY();break;case MotionEvent.ACTION_MOVE:stopx=event.getX();stopy=event.getY();canvas.drawLine(startx, starty, stopx, stopy, paint);startx=event.getX();starty=event.getY();iv.setImageBitmap(copybitmap);break;case MotionEvent.ACTION_UP:break;}return true;}});
这样基本事件都完成了 。
文章插图
.class
package com.verney.board;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Bitmap.Config;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ImageView;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;public class MainActivity extends Activity {private Bitmap basebitmap,copybitmap;private Bitmap bitmap;private Canvas canvas;private Paint paint;ImageView iv;TextView huaxian;private float startx,starty;SeekBar seekbar;public void red(View view){paint.setColor(Color.RED);}public void green(View view){paint.setColor(Color.GREEN);}public void blue(View view){paint.setColor(Color.BLUE);}public void xiangpi(View view){paint.setColor(Color.WHITE);}protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);iv=(ImageView) findViewById(R.id.iv);seekbar=(SeekBar) findViewById(R.id.seekbar);//basebitmap=BitmapFactory.decodeResource(getResources(), R.drawable.);//canvasinit();seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubint progress=seekBar.getProgress();float count=progress/2f;paint.setStrokeWidth(count);}public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}});iv.setOnTouchListener(new OnTouchListener() {public boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:startx=event.getX();starty=event.getY();break;case MotionEvent.ACTION_MOVE:float stopx=event.getX();float stopy=event.getY();canvas.drawLine(startx, starty, stopx, stopy, paint);startx=event.getX();starty=event.getY();iv.setImageBitmap(copybitmap);break;case MotionEvent.ACTION_UP:break;}return true;}});}private void init() {basebitmap=BitmapFactory.decodeResource(getResources(), R.drawable.bg);copybitmap=Bitmap.createBitmap(basebitmap.getWidth(),basebitmap.getHeight(),basebitmap.getConfig());canvas=new Canvas(copybitmap);//设置画板颜色canvas.drawColor(Color.WHITE);paint=new Paint();//设置画笔颜色//paint.setColor(Color.RED);//设置画笔粗细paint.setStrokeWidth(0);iv.setImageBitmap(copybitmap);//设置画笔风格//paint.setStyle(Style.STROKE);}}
- 1、学习三极管的使用
- 岗位内推 | 小红书商业广告部门招聘广告算法、广告系统开发工程师
- OpenCV学习笔记--第一个OpenCV程序:图片读写显示
- android-沉浸状态栏以及状态栏背景色如何设置
- 如何将android studio设置复位,将设置恢复到初始化
- 小米android10升级版本
- androidGPS驱动
- 【论文笔记】CHI '16 Embracing Error to Enable
- 自然笔记:旅人徐霞客 面点奇人吉尼斯记录
- TI-BASIC 计算器游戏开发之文字、图形、音频教程:前言