简体   繁体   中英

Touch listener on framelayout and scrollview on inflated layout issue

I am doing a flip card application in which i have applied onTouchListener on my frame layout. By using singletap gesturelistener i am flipping card from front to back and vice versa. Every thing is working fine. As my data is large i have to introduce scroll view on my inflated layouts.

setContentView(R.layout.flashframe);
cardView = (FrameLayout)findViewById(R.id.container);
    cardView.setOnTouchListener(this);
    mGestureDetector=new GestureDetector(this.getBaseContext(), new MyGestureListener(this));
    if(savedInstanceState==null){
        getFragmentManager().beginTransaction()
                .add(R.id.container, new CardFrontFragment()).commit();
        cardNumber=1;
        setCard(cardNumber);
    }
@Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    mGestureDetector.onTouchEvent(event);
    return true;
}
 public class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
    public MyGestureListener(OpenClass openClass) {
        // TODO Auto-generated constructor stub
    }
            @Override
    public boolean onSingleTapUp(MotionEvent me)
    {
        flipCard();
        return true;
    }
    }

XML Layout :-

   <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:weightSum="100" android:layout_height="match_parent">
    <ScrollView android:layout_weight="30" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:text="To be retrieved from sqlite"
            android:layout_width="match_parent"       android:layout_height="match_parent"></TextView>
        </ScrollView>
</LinearLayout>

Frame Layout:-

  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

When i am inflating my layout with scroll view, gesture listener is not responding whereas scroll view is working on front card. I am unnable to flip, if i am using scroll view.

Please help me, how i can solve this..

You should override the ScrollView's onTouchListener. In it you can check whenever to flip your card or scroll...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM