欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android實(shí)現(xiàn)手寫簽名功能

 更新時(shí)間:2019年11月29日 15:09:01   作者:黃俄白  
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)手寫簽名功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android手寫簽名展示的具體代碼,供大家參考,具體內(nèi)容如下

代碼簡(jiǎn)單,就不發(fā)demo了,直接貼代碼

package com.xx;
 
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.xx.R;
 
/**
 * Description: 簽名類
 * Copyright:  Copyright (c)2018
 * Company:   
 * author:   Corwin
 * version:   1.0
 * date:    2018/9/5 18:32
 * Modification History:
 * Date     Author   Version   Description
 * ------------------------------------------------------------------
 * 2018/9/5  Corwin   1.0     1.0 Version
 */
public class SignatureActivity extends AppCompatActivity {
 
 private ImageView imageSign;
 private SignatureView mView;
 
 @Override public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_signature);
 
  imageSign = findViewById(R.id.iv_sign);
  FrameLayout frameLayout = findViewById(R.id.fl_view);
 
  mView = new SignatureView(this);
  frameLayout.addView(mView);
  mView.requestFocus();
 
  Button btnClear = findViewById(R.id.btn_clear);
  btnClear.setOnClickListener((v) -> {
    mView.clear();
  });
 
  Button btnOk = findViewById(R.id.btn_ok);
  btnOk.setOnClickListener((v) -> {
    Bitmap imageBitmap = mView.getCachebBitmap();
    imageSign.setImageBitmap(imageBitmap);
  });
 }
 
 /**
  * 自定義簽名控件
  */
 class SignatureView extends View {
 
  //畫筆
  private Paint paint;
 
  //畫布
  private Canvas cacheCanvas;
 
  //位圖
  private Bitmap cachebBitmap;
 
  //圖片保存路徑
  private Path path;
 
  //位圖緩存
  public Bitmap getCachebBitmap() {
   return cachebBitmap;
  }
 
  public SignatureView(Context context) {
   super(context);
   init();
  }
 
  /**
   * 初始化
   */
  private void init() {
   //設(shè)置畫筆
   paint = new Paint();
   paint.setAntiAlias(true);
   paint.setStrokeWidth(3);
   paint.setStyle(Paint.Style.STROKE);
   paint.setColor(Color.BLACK);
   path = new Path();
 
   //創(chuàng)建位圖
   cachebBitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
 
   //用自定義位圖構(gòu)建畫布
   cacheCanvas = new Canvas(cachebBitmap);
   //設(shè)置畫布為白色
   cacheCanvas.drawColor(Color.WHITE);
  }
 
  /**
   * 清除畫板,重置畫筆
   */
  public void clear() {
   if (cacheCanvas != null) {
    paint.setColor(Color.WHITE);
    cacheCanvas.drawPaint(paint);
    paint.setColor(Color.BLACK);
    cacheCanvas.drawColor(Color.WHITE);
    invalidate();
   }
  }
 
  @Override protected void onDraw(Canvas canvas) {
   canvas.drawBitmap(cachebBitmap, 0, 0, null);
   canvas.drawPath(path, paint);
  }
 
  @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
 
   int curW = cachebBitmap != null ? cachebBitmap.getWidth() : 0;
   int curH = cachebBitmap != null ? cachebBitmap.getHeight() : 0;
   if (curW >= w && curH >= h) {
    return;
   }
 
   if (curW < w) curW = w;
   if (curH < h) curH = h;
   Bitmap newBitmap = Bitmap.createBitmap(curW, curH, Bitmap.Config.ARGB_8888);
   Canvas newCanvas = new Canvas();
   newCanvas.setBitmap(newBitmap);
   if (cachebBitmap != null) {
    newCanvas.drawBitmap(cachebBitmap, 0, 0, null);
   }
   cachebBitmap = newBitmap;
   cacheCanvas = newCanvas;
  }
  private float cur_x, cur_y;
  @Override public boolean onTouchEvent(MotionEvent event) {
   float x = event.getX();
   float y = event.getY();
   switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN: {
     cur_x = x;
     cur_y = y;
     path.moveTo(cur_x, cur_y);
     break;
    }
    case MotionEvent.ACTION_MOVE: {
     path.quadTo(cur_x, cur_y, x, y);
     cur_x = x;
     cur_y = y;
     break;
    }
    case MotionEvent.ACTION_UP: {
     cacheCanvas.drawPath(path, paint);
     path.reset();
     break;
    }
   }
   invalidate();
   return true;
  }
 }
}

布局文件:

<?xml version="1.0"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  >
 <ImageView
   android:id="@+id/iv_sign"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_gravity="center"
   android:layout_marginBottom="3dp"
   android:layout_weight="1"
   android:background="@color/white"
   />
 <FrameLayout
   android:id="@+id/fl_view"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:background="@color/white"
   />
 <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@android:drawable/bottom_bar"
   android:paddingTop="3dp"
   >
  <Button
    android:id="@+id/btn_ok"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="確定"
    />
  <Button
    android:id="@+id/btn_clear"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="清除"
    />
 </LinearLayout>
</LinearLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android自定義button點(diǎn)擊效果的兩種方式

    Android自定義button點(diǎn)擊效果的兩種方式

    這篇文章主要為大家詳細(xì)介紹了Android自定義button點(diǎn)擊效果的兩種方式,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android實(shí)現(xiàn)修改狀態(tài)欄背景、字體和圖標(biāo)顏色的方法

    Android實(shí)現(xiàn)修改狀態(tài)欄背景、字體和圖標(biāo)顏色的方法

    本篇文章主要介紹了Android實(shí)現(xiàn)修改狀態(tài)欄背景、字體和圖標(biāo)顏色的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • Android 自定義輸入支付密碼的軟鍵盤實(shí)例代碼

    Android 自定義輸入支付密碼的軟鍵盤實(shí)例代碼

    這篇文章主要介紹了Android 自定義輸入支付密碼的軟鍵盤實(shí)例代碼的相關(guān)資料,并附簡(jiǎn)單實(shí)例代碼和實(shí)現(xiàn)效果圖,需要的朋友可以參考下
    2016-11-11
  • kotlin開發(fā)cli工具小技巧詳解

    kotlin開發(fā)cli工具小技巧詳解

    這篇文章主要為大家介紹了kotlin開發(fā)cli工具小技巧詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • 用Kotlin打造一個(gè)Router的示例代碼

    用Kotlin打造一個(gè)Router的示例代碼

    本篇文章主要介紹了用Kotlin打造一個(gè)Router的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Android實(shí)現(xiàn)輪詢的三種方式

    Android實(shí)現(xiàn)輪詢的三種方式

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)輪詢的三種方式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • wenserver獲取天氣預(yù)報(bào)數(shù)據(jù)實(shí)例分享

    wenserver獲取天氣預(yù)報(bào)數(shù)據(jù)實(shí)例分享

    wenserver獲取天氣預(yù)報(bào)數(shù)據(jù),實(shí)現(xiàn)android顯示天氣信息
    2013-12-12
  • 在Android中高效的加載大圖的方法示例

    在Android中高效的加載大圖的方法示例

    本篇文章主要介紹了在Android中高效的加載大圖的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • Android端實(shí)現(xiàn)單點(diǎn)登錄的方法詳解

    Android端實(shí)現(xiàn)單點(diǎn)登錄的方法詳解

    所謂單點(diǎn)登錄就是指的同一個(gè)賬戶(id)不能在一個(gè)以上的設(shè)備上登錄對(duì)應(yīng)的用戶系統(tǒng)(排除web端和移動(dòng)端可以同時(shí)登錄的情況),例如:用戶m在A設(shè)備登錄并保持登錄狀態(tài),然后又在B設(shè)備登錄,此時(shí)A應(yīng)該要強(qiáng)制下線,m無(wú)法在A設(shè)備上繼續(xù)執(zhí)行用戶相關(guān)的操作,下面來(lái)一起看看吧。
    2016-11-11
  • Android 如何在私有空間創(chuàng)建文件

    Android 如何在私有空間創(chuàng)建文件

    在Android應(yīng)用程序中,我們經(jīng)常需要在私有空間中創(chuàng)建文件來(lái)存儲(chǔ)應(yīng)用數(shù)據(jù),例如用戶配置文件、日志文件等,本文將介紹如何在Android應(yīng)用中使用Java代碼創(chuàng)建文件并將其保存在私有空間中,感興趣的朋友跟隨小編一起看看吧
    2024-06-06

最新評(píng)論