2011-06-09 117 views
0

我的应用程序需要2滚动视图(sv1,sv2)。 sv1是主滚动视图,sv2是sv1的子滚动视图。 有可能吗?那么该怎么做。android-如何把滚动视图下滚动视图

以下是我的答案。它仅在模拟器中工作,但在设备中不工作意味着设备支持sv1只有sv2不工作。

怎么办?

感谢

回答

0
<ScrollView android:id=”@+id/parent_scroll” 
     android:layout_width=”fill_parent” 
     android:layout_height=”wrap_content” 
     android:layout_weight=”1″ 
     android:background=”@drawable/dotted_bg” 
     android:focusableInTouchMode=”false”> 
        <LinearLayout /> 
        <LinearLayout /> 
        <LinearLayout > 
        <ScrollView android:id=”@+id/child_scroll” 
        android:layout_width=”fill_parent” 
        android:layout_height=”fill_parent” 
        android:background=”@drawable/text_box_bg”> 
       <TextView android:id=”@+id/text_description” 
        android:layout_width=”fill_parent” 
        android:layout_height=”fill_parent” 
        android:textColor=”@color/gray” 
        android:textSize=”12dip” 
        android:padding=”5dip” 
        android:scrollbars=”vertical”/> 
       <!–ScrollView> 
       </LinearLayout> 

步骤1:提供独特的ID既滚动视图。 第2步:获取活动中的两个滚动视图的引用。

parentScroll=(ScrollView)findViewById(R.id.parent_scroll); 
childScroll=(ScrollView)findViewById(R.id.child_scroll); 

第3步:现在设置两个触摸侦听器。

 parentScroll.setOnTouchListener(new View.OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) { 
       Log.v(TAG,”PARENT TOUCH”); 
       findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false); 
       return false; 
      } 
     }); 
     childScroll.setOnTouchListener(new View.OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) 
      { 
       Log.v(TAG,”CHILD TOUCH”); 
            // Disallow the touch request for parent scroll on touch of child view 
       v.getParent().requestDisallowInterceptTouchEvent(true); 
       return false; 
      } 
     }); 

做...