网站建设资讯

NEWS

网站建设资讯

android手势-创新互联

一丶首先创建一个手势库

创新互联是一家专注于成都网站建设、成都网站设计与策划设计,双河网站建设哪家好?创新互联做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:双河等地区。双河做网站价格咨询:18982081108

二丶手势实例

  1. 布局文件:

    在布局文件中有:

           android:id="@+id/gv"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#000000"
           android:gestureStrokeWidth="10"
           android:gestureColor="#ff0000"
           />

  2. MainActivity中

    public class MainActivity extends Activity {

       private GestureOverlayView gv;//手势控件
       private GestureLibrary gestureLibrary;//加载手势库
       private boolean loadStatus;
       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          //拿到控件
          gv = (GestureOverlayView) findViewById(R.id.gv);
          //创建加载手势库的工具
          gestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
          //加载手势库
          loadStatus = gestureLibrary.load();
          //给gv加一个监听器
          //监听一种手势
          gv.addOnGesturePerformedListener(new OnGesturePerformedListener() {

             @Override
             public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
                //手势加载成功
                if(loadStatus){
                   //识别手势 Prediction(手势相似度)
                   ArrayList pres = gestureLibrary.recognize(gesture);
                   if(!pres.isEmpty()){
                      Prediction pre = pres.get(0);
                      if(pre.score > 6){
                         if("close".equals(pre.name)){
                            finish();
                         }else if("tel".equals(pre.name)){
                            //打电话
                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_CALL);
                            intent.setData(Uri.parse("tel://110"));
                            startActivity(intent);
                         }else if("right".equals(pre.name)){
                            Toast.makeText(getApplicationContext(), "正确", 0).show();
                         }
                      }else{
                         Toast.makeText(getApplicationContext(), "手势不匹配", 0).show();
                      }
                   }else{
                      Toast.makeText(MainActivity.this, "手势库加载失败", 0).show() ;
                   }

                }
             }
          });
       }
    }

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:android手势-创新互联
URL地址:http://cdweb.net/article/jpjdo.html