1

これは私のレイアウト xml ファイルです。

     ...
<RelativeLayout 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:id="@+id/rlt" >

    <TextView
    android:id="@+id/title_text"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" 
    android:textSize="22dp"
    android:layout_centerHorizontal="true"
    android:textColor ="#add8e6"
    />  

<TextView 
 android:id="@+id/description"   
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_below="@+id/tatle_text"
 android:layout_marginTop="45dp"
 android:textColor = "#e3e4fa"
 android:autoLink="email"
 android:textColorLink="#fdd017"
  />
     ...
     ...
     ...
     ...


これは私のonFling()です:

   SimpleOnGestureListener simpleOnGestureListener
           = new SimpleOnGestureListener(){
          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
           float velocityY) {
          // TODO Auto-generated method stub

             final float xDistance = Math.abs(e1.getX() - e2.getX());
              final float yDistance = Math.abs(e1.getY() - e2.getY());

              if(xDistance > gs.swipe_Max_Distance || yDistance > gs.swipe_Max_Distance)
              return false;
               Log.v("Help_developers", "Flinging baby!");
              velocityX = Math.abs(velocityX);
              velocityY = Math.abs(velocityY);
                    boolean result = false;

              if(velocityX > gs.swipe_Min_Velocity && xDistance > gs.swipe_Min_Distance){
               if(e1.getX() > e2.getX()) // right to left
               { //Slide to Help_app
                   Intent i=new Intent(Help_developers.this,Help_app.class);
                   startActivity(i);
                finish();
               }
               else
               {
                 //Slide to Help_qanda
                   Intent i=new Intent(Help_developers.this,Help_pending.class);
                   startActivity(i);
               finish();
               }

               result = true;
              }


               return result;
         }
    });
 final GestureDetector gestureDetector
       = new GestureDetector(simpleOnGestureListener);
      rlt.setOnTouchListener(new View.OnTouchListener()
         {
                public boolean onTouch(View view, MotionEvent event) {
                    Log.d("test", "clicked!");
                    if(gestureDetector.onTouchEvent(event))  {
                        Log.d("test", "gesture detected");
                        return true;
                    }

                    return false;
                }
            });


rlt は RelativeLayout の ID ですrltonFling()
でのフリンジは、 id のテキスト ビューで属性 android:autoLink="email" では機能しません。しかし、その属性を削除すると、フリングが機能します。なぜこれが起こっているのか分かりません。その属性はフリング ジェスチャにどのように影響しますか? EDIT自体 の onTouch() は呼び出されません。ログが logcat に記録されることはありません。属性 android:autoLink="email" が存在する場合。 完全なレイアウト XML ファイル:description

GestureListener

  <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
                 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >


     <RelativeLayout 
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@+id/rlt" >

        <TextView
        android:id="@+id/title_text"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" 
        android:textSize="22dp"
        android:layout_centerHorizontal="true"
        android:textColor ="#ffffff"

        />  

    <TextView 
     android:id="@+id/description"   
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_below="@+id/tatle_text"
     android:layout_marginTop="45dp"
     android:textColor = "#e3e4fa"
     android:autoLink="email"
     android:textColorLink="#fdd017"
     android:
      />
<View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rlt_touch" />

    <Button
            android:id="@+id/Home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/home"
            android:text="Home"
          />

    </RelativeLayout>

    </ScrollView>
4

2 に答える 2

1

最初の回答のようにTextViewでタッチ処理をオフにする代わりに、透明なビュー(RelativeLayoutの最上位の子として)を追加してタッチイベントをキャプチャし、関連するイベントを選択的にTextViewに転送しながら取得できます。ジェスチャを検出するためのすべてのイベント:

  • XMLレイアウトを変更し、タッチキャプチャビューを追加します。

    ...
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rlt">
    
        <TextView
            android:id="@+id/title_text"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="22dp"
            android:layout_centerHorizontal="true"
            android:textColor="#add8e6"
            android:background="#ff0000" />
    
        <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/title_text"
            android:layout_marginTop="45dp"
            android:textColor="#e3e4fa"
            android:textColorLink="#fdd017"
            android:autoLink="email" />
    
        <!-- our touch-capturing view -->
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/rlt_touch" />
    
    </RelativeLayout>
    ...
    
  • Javaコードを変更し、代わりにOnTouchListenerを追加されたrlt_touchビューに設定し、イベント転送コードを追加します。

    final View rt = findViewById(R.id.rlt_touch);
    final TextView tv = (TextView) findViewById(R.id.description);
    
    rt.setOnTouchListener(new OnTouchListener() {
        final Rect r = new Rect();
        final Point p1 = new Point();
        final Point p2 = new Point();
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.d("test", "clicked!");
    
            if (gestureDetector.onTouchEvent(event)) {
                Log.d("test", "gesture detected");
            }
    
            // offset touch location into the TextView and forward it if relevant
            rt.getGlobalVisibleRect(r, p2);
            tv.getGlobalVisibleRect(r, p1);
            event.offsetLocation(p2.x - p1.x, p2.y - p1.y);
            if (r.contains((int) event.getRawX(), (int) event.getRawY())) {
                tv.onTouchEvent(event);
            }
    
            return true;
        }
    });
    
于 2012-10-05T03:13:35.280 に答える
0

TextView を設定android:autoLink="email"すると、タッチ イベントの消費が開始され、OnTouchListener がイベントを受け取るかどうかに影響します。

常にイベントを取得できるように、いくつかの変更を試すことができます。

  • TextViewの属性を false に設定しandroid:linksClickableます。

    ...
    android:autoLink="email"
    android:linksClickable="false"
    ...
    
  • OnTouchListener を変更して、常に true を返すようにします。

    rlt.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.d("test", "clicked!");
            if (gestureDetector.onTouchEvent(event)) {
                Log.d("test", "gesture detected");
            }
            return true;
        }
    });
    
于 2012-10-03T16:53:12.557 に答える