最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AndroidStudio:手勢(shì)識(shí)別

 更新時(shí)間:2019年04月19日 16:03:14   作者:Allison李沛  
這篇文章主要介紹了AndroidStudio手勢(shì)識(shí)別,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

一內(nèi)容:設(shè)計(jì)一個(gè)手寫字體識(shí)別程序。

二實(shí)現(xiàn)

①建立一個(gè)存放手寫字體的數(shù)據(jù)庫

②activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"
  android:orientation="vertical">
 
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Gesture:"
    android:id="@+id/tv"
    android:textSize="24dp"/>
 
  <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20dp"
    android:text="clear"
    android:id="@+id/bt"/>
 
  <android.gesture.GestureOverlayView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gestureStrokeType="multiple"
    android:eventsInterceptionEnabled="false"
    android:orientation="vertical"
    android:id="@+id/gesture"></android.gesture.GestureOverlayView>
</LinearLayout

3.MainActivity.java

package com.example.myapplication;
 
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
 
import java.util.ArrayList;
 
public class MainActivity extends AppCompatActivity implements GestureOverlayView.OnGesturePerformedListener {
  GestureLibrary mLibrary; //定義手勢(shì)庫對(duì)象
  GestureOverlayView gest; //定義手勢(shì)視圖對(duì)象做畫板之用
  TextView txt;
  Button bt;
 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 
    gest = (GestureOverlayView)findViewById(R.id.gesture);
    gest.addOnGesturePerformedListener(this); // 注冊(cè)手勢(shì)識(shí)別的監(jiān)聽器
    txt = (TextView)findViewById(R.id.tv);
    mLibrary = GestureLibraries.fromRawResource(this,R.raw.gestures); //加載手勢(shì)庫
    bt = (Button)findViewById(R.id.bt);
    bt.setOnClickListener(new Click());
 
    if (!mLibrary.load()) {
      finish();
    }
  }
    /*根據(jù)畫的手勢(shì)識(shí)別是否匹配手勢(shì)庫里的手勢(shì)*/
  @Override
  public void onGesturePerformed(GestureOverlayView gest, Gesture gesture) {
    ArrayList gestList = mLibrary.recognize(gesture); // 從手勢(shì)庫獲取手勢(shì)數(shù)據(jù)
    if (gestList.size() > 0) {
      Prediction pred = (Prediction)gestList.get(0);
      if (pred.score > 1.0) {  // 檢索到匹配的手勢(shì)
        Toast.makeText(this,pred.name,Toast.LENGTH_SHORT).show();
        txt.append(pred.name);
      }
    }
  }
 
  private class Click implements View.OnClickListener {
    @Override
    public void onClick(View view) {
      txt.setText("Gesture:");
    }
  }
}

三效果

以上所述是小編給大家介紹的AndroidStudio手勢(shì)識(shí)別詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

抚远县| 阿克陶县| 黑龙江省| 那曲县| 普洱| 平乡县| 韩城市| 汉源县| 阜南县| 万源市| 鹤岗市| 甘肃省| 安溪县| 绩溪县| 方城县| 大石桥市| 鄂托克前旗| 景德镇市| 高州市| 宣武区| 依安县| 乐亭县| 页游| 萝北县| 丰宁| 阿坝| 陕西省| 丰原市| 府谷县| 富锦市| 雅江县| 泰宁县| 常山县| 罗甸县| 张家界市| 灌云县| 永安市| 丘北县| 绥阳县| 丹巴县| 读书|