在屏幕上的任意位置滑动Android

问题描述:

我使用setOnTouchlistner类来检测左右滑动。我可以让它在listview上正常工作,但listview太小而不能每次都刷新一次。在屏幕上的任意位置滑动Android

然后我尝试将刷卡设置为主LinearLayout。在这里面我有另外三个LinearLayout。但它不工作感谢任何帮助。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:baselineAligned="false" 
android:orientation="horizontal" 
android:id="@+id/driveView" 
android:focusableInTouchMode="true" 
android:focusable="true" 
android:clickable="true"> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

下面是代码:

private LinearLayout myView = null; 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.drive); 
myView = (LinearLayout)findViewById(R.id.driveView); 

myView.setOnTouchListener(new OnSwipeTouchListener(mContext) { 
     @Override 
     public void onSwipeLeft() { 
      showdrivedialog(mContext, "Drive List", "Change to Ascending list!"); 
     } 

     public void onSwipeRight() { 
       showdrivedialog(mContext, "Drive List", "Change to Descending list!"); 
     } 
    }); 
+0

如果此视图具有触摸监听器的子视图,则需要在它们上返回false,以便此视图可以获得触摸 – Xjasz 2015-03-19 01:30:46

+0

其他视图都不具有触摸监听器,我有onClickListner,onFocusChangeListner,onEditorActionListner和OnItemClickListner。谢谢。 – 2015-03-19 20:17:05

两个问题我想提一提。

1)我不知道OnSwipeTouchListener,但我有兴趣。我怀疑android:clickable="true"应该是错误的,因为滑动和点击之间似乎存在冲突。

2)看看这个SO链接@How to handle right to left swipe gestures。我不知道你在哪里得到OnSwipeTouchListener类,但你可以用274票复制它!

我个人并没有使用这个类。我已经使用并扩展了Horizo​​ntalScrollView

+0

我尝试将clickable设置为false,但在另一个帖子中,有人通过将其设置为true来使其工作。这是相同的OnSwipeTouchListener。 – 2015-03-19 20:08:30