这是我的布局 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 rlt
。
现在onFling()中的投掷不适用于带有 id 的文本视图中的属性 android:autoLink="email"description
。但是当我删除该属性时,一掷千金。我不知道为什么会这样。该属性如何影响投掷手势?
编辑
本身
的 onTouch()GestureListener
没有被调用。日志永远不会记录在 logcat 中。当属性 android:autoLink="email" 存在时。
完整的布局 XML 文件:
<?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>