2012-01-19 33 views
0

我已经在我的应用程序中实现了具有8个子视图的ViewFlipper,如下所示。ViewFlipper中的滚动视图强制onFling手势不起作用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:background="@drawable/main_bg" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ViewFlipper 
    android:id="@+id/layout_tab_one" 
    android:layout_marginTop="70dp" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <include 
     layout="@layout/exterior_driverside_1" 
     /> 
    <include 
     layout="@layout/exterior_driverside_2" 
     /> 
    <include 
     layout="@layout/exterior_front_1" 
     /> 
    <include 
     layout="@layout/exterior_front_2" 
     /> 
    <include 
     layout="@layout/exterior_passenger_1" 
     /> 
    <include 
     layout="@layout/exterior_passenger_2" 
     /> 
    <include 
     layout="@layout/exterior_rear_1" 
     /> 
    <include 
     layout="@layout/interior_1" 
     /> 
    <include 
     layout="@layout/interior_2" 
     /> 
    <include 
     layout="@layout/interior_3" 
     /> 
    <include 
     layout="@layout/interior_4" 
     /> 
    <include 
     layout="@layout/interior_5" 
     /> 
    <include 
     layout="@layout/finalpage" 
     /> 
</ViewFlipper> 
</LinearLayout> 

每个孩子的布局类似于这样。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <TextView 
        android:id="@+id/check_title" 
        android:layout_marginTop="10dp" 
        android:textColor="#ffffff" 
        android:textStyle="bold" 
        android:layout_marginRight="10dp" 
        android:textSize="18sp" 
        android:layout_alignParentLeft="true" 
        android:layout_marginLeft="25dp" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Exterior/Rear  " 
        /> 
     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/greytop_bg" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:layout_marginLeft="7dp" 
      android:layout_marginRight="7dp" 
      > 


       <TextView 
        android:id="@+id/tailights_txt" 
        android:textColor="#ffffff" 
        android:text="Tailights" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        /> 
        <CheckBox 
         android:id="@+id/tailights" 
         android:checked="false" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:layout_alignParentRight="true" /> 
        <EditText 
         android:id="@+id/tailights_edit" 
         android:layout_width="fill_parent" 
         android:layout_height="30dp" 
         android:layout_below="@+id/tailights" 
         android:background="@drawable/edit_text" 
         android:hint="Tap to enter comments" 
         android:textSize="10dp" 
         android:visibility="gone" 
         /> 
       </RelativeLayout> 
      <RelativeLayout  
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/greymid_bg" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:layout_marginLeft="7dp" 
      android:layout_marginRight="7dp" > 
       <TextView 
        android:id="@+id/bootlid_txt" 
        android:textColor="#ffffff" 
        android:text="Boot lid/Tailgate" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="10dp"/> 
        <CheckBox 
         android:id="@+id/bootlid" 
         android:checked="false" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:layout_alignParentRight="true"/> 
        <EditText 
         android:id="@+id/bootlid_edit" 
         android:layout_width="fill_parent" 
         android:layout_height="30dp" 
         android:layout_below="@+id/bootlid" 
         android:background="@drawable/edit_text" 
         android:hint="Tap to enter comments" 
         android:textSize="10dp" 
         android:visibility="gone" 
         /> 
       </RelativeLayout> 
       <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/greymid_bg" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:layout_marginLeft="7dp" 
      android:layout_marginRight="7dp" > 
       <TextView 
        android:id="@+id/bumperbar_txt" 
        android:textColor="#ffffff" 
        android:text="Bumper Bar" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        /> 
        <CheckBox 
         android:id="@+id/bumperbar" 
         android:checked="false" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:layout_alignParentRight="true"/> 
        <EditText 
         android:id="@+id/bumperbar_edit" 
         android:layout_width="fill_parent" 
         android:layout_height="30dp" 
         android:layout_below="@+id/bumperbar" 
         android:background="@drawable/edit_text" 
         android:hint="Tap to enter comments" 
         android:textSize="10dp" 
         android:visibility="gone" 
         /> 
</RelativeLayout> 
<RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/greymid_bg" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:layout_marginLeft="7dp" 
      android:layout_marginRight="7dp" > 
       <TextView 
        android:id="@+id/mudflaps_txt" 
        android:textColor="#ffffff" 
        android:text="Mud Flaps" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        /> 
        <CheckBox 
         android:id="@+id/mudflaps" 
         android:checked="false" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:layout_alignParentRight="true"/> 
        <EditText 
         android:id="@+id/mudflaps_edit" 
         android:layout_width="fill_parent" 
         android:layout_height="30dp" 
         android:layout_below="@+id/mudflaps" 
         android:background="@drawable/edit_text" 
         android:hint="Tap to enter comments" 
         android:textSize="10dp" 
         android:visibility="gone" 
         /> 
</RelativeLayout> 
<RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/greybott_bg" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:layout_marginLeft="7dp" 
      android:layout_marginRight="7dp" > 
       <TextView 
        android:id="@+id/rear_unapproved_txt3" 
        android:textColor="#ffffff" 
        android:text="Unapproved advertising" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="10dp" 
        /> 
        <CheckBox 
         android:id="@+id/rear_unapproved3" 
         android:checked="false" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:layout_alignParentRight="true"/> 
        <EditText 
         android:id="@+id/rear_unapproved_edit3" 
         android:layout_width="fill_parent" 
         android:layout_height="30dp" 
         android:layout_below="@+id/rear_unapproved3" 
         android:background="@drawable/edit_text" 
         android:hint="Tap to enter comments" 
         android:textSize="10dp" 
         android:visibility="gone" 
         /> 
</RelativeLayout> 
</LinearLayout> 

我已经实现onGestureListener(onFling)来切换ViewFlipper的另一个子视图。如果我为每个子视图添加ScrollView,onFling不起作用。但是每个子视图都需要一个滚动视图。如何在ViewFlipper中实现ScrollView?如果有人为我推荐一些代码,那将会很棒。

回答

3

希望this帮助你

@Override 
public boolean dispatchTouchEvent(MotionEvent ev){ 
    super.dispatchTouchEvent(ev);  
    return productGestureDetector.onTouchEvent(ev); 
} 
0

是的,这确实有效。如果不处理查看鳍状肢适配器的轻扫手势,Textview会在有溢出时自动滚动。所以,当你自己处理滑动手势,让你的TextView滚动通过添加

mTextView.setMovementMethod(new ScrollingMovementMethod()); 

并添加上面显示的dispatchtouchevent功能,在您的活动。