Android实现签名涂鸦手写板

2022-08-10,,,

本文实例为大家分享了android实现签名涂鸦手写板的具体代码,供大家参考,具体内容如下

布局文件

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

  <framelayout
    android:id="@+id/fl_signature"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_marginleft="20dp"
    android:layout_marginright="20dp"
    android:layout_margintop="10dp"
    android:background="@drawable/singature_bg"
    android:gravity="top">
  </framelayout>
  <imageview
    android:id="@+id/iv_signature"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_marginleft="20dp"
    android:layout_marginright="20dp"
    android:layout_margintop="10dp"
    android:background="@drawable/signature_shape"
    android:gravity="top"
    android:visibility="gone"/>

  <relativelayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margintop="20dp"
        android:layout_marginbottom="20dp">

        <textview
          android:id="@+id/tv_revert_signature"
          android:layout_width="100dp"
          android:layout_height="35dp"
          android:layout_alignparentright="true"
          android:layout_marginright="140dp"
          android:background="@drawable/btn_order_details_pay_bg"
          android:gravity="center"
          android:paddingleft="30dp"
          android:paddingright="30dp"
          android:text="重签"
          android:textcolor="@color/code_number_bg"
          android:textsize="@dimen/text_title_word" />

        <textview
          android:id="@+id/tv_signature_save"
          android:layout_width="100dp"
          android:layout_height="35dp"
          android:layout_alignparentright="true"
          android:layout_marginright="20dp"
          android:background="@drawable/bt_bg"
          android:gravity="center"
          android:paddingleft="30dp"
          android:paddingright="30dp"
          android:text="保存"
          android:textcolor="@color/white"
          android:textsize="@dimen/text_title_word" />

      </relativelayout>



</linearlayout>

//开始签名

private void startsignature() {
    // 获取屏幕尺寸
    displaymetrics mdisplaymetrics = new displaymetrics();
    getwindow().getwindowmanager().getdefaultdisplay().getmetrics(mdisplaymetrics);
  }

  @override
  public void onwindowfocuschanged(boolean hasfocus) {
    super.onwindowfocuschanged(hasfocus);
    if(hasfocus&&mpaintview==null){
      int screenwidth = mfl_signature.getmeasuredwidth();
      int screenheight = mfl_signature.getmeasuredheight();
      mpaintview=new paintview(getapplicationcontext(),screenwidth, screenheight);
      mfl_signature.addview(mpaintview);
      mpaintview.requestfocus();
    }
  }

//创建签名文件

private void createsignfile() {

    fileoutputstream fos = null;

    file file = null;
    try {
      path= generateimgepath();
      file = new file(path);
      fos = new fileoutputstream(file);

      //如果设置成
      mpaintbitmap.compress(bitmap.compressformat.jpeg, 100, fos);
    } catch (ioexception e) {
      e.printstacktrace();
    } finally {
      try {
        if (fos != null) {
          fos.close();
        }

      } catch (ioexception e) {
        e.printstacktrace();
      }
    }
  }

//重新签名

if (mpaintview.getpath().isempty()){
          toastutils.showshort(this,"您还没有签名呦");
        }else {
          mpaintview.clear();

        }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

《Android实现签名涂鸦手写板.doc》

下载本文的Word格式文档,以方便收藏与打印。