Использование Viewflipper с Gridview - PullRequest
1 голос
/ 28 сентября 2011

Я создал календарь, который работает нормально, используя GridView, который имеет OnClickListener. Теперь я обернул два GridViews в ViewFlipper. ViewFlipper имеет OnTouchListener, который также отлично работает, я могу изменить вид с помощью ontouch при перетаскивании. Проблема в том, что мне нужно перетащить пространство EMTPY в Activity, чтобы использовать ViewFlipper. Когда я перетаскиваю GridView, ничего не происходит вообще. Но я могу нажать на GridView для OnClickListener.

XML:

<ViewFlipper android:id="@+id/details"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
      <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
    <GridView
        android:id="@+id/weeks"
        android:numColumns="1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="8">
    </GridView>
    <GridView
        android:id="@+id/calendar"
        android:numColumns="7"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    </GridView>
</LinearLayout>

код Android:

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
    // Get the action that was done on this touch event
    switch (arg1.getAction())
    {
        case MotionEvent.ACTION_DOWN:
        {
            // store the X value when the user's finger was pressed down
            downXValue = arg1.getX();
            break;
        }

        case MotionEvent.ACTION_UP:
        {
            // Get the X value when the user released his/her finger
            currentX = arg1.getX();    


            // going backwards: pushing stuff to the right
            if (currentX - downXValue < -(arg0.getWidth()/3))
            {
                mdh.nextMonth();
                calendar.add(Calendar.MONTH, 1);
                currentMonth.setText(new SimpleDateFormat("MMMM yyyy").format(calendar.getTime()));
                cAdapter.notifyDataSetChanged();
                updateWeeks();
                 // Set the animation
                 vf.setInAnimation(arg0.getContext(), R.anim.push_left_in);
                  vf.setOutAnimation(arg0.getContext(), R.anim.push_left_out);
                  // Flip!
                  vf.showPrevious();
            }

            // going forwards: pushing stuff to the left
            if (currentX - downXValue > arg0.getWidth()/3)
            {
                mdh.previousMonth();
                calendar.add(Calendar.MONTH, -1);
                currentMonth.setText(new SimpleDateFormat("MMMM yyyy").format(calendar.getTime()));
                cAdapter.notifyDataSetChanged();
                updateWeeks();
                 // Set the animation
                vf.setInAnimation(arg0.getContext(), R.anim.push_right_in);
                vf.setOutAnimation(arg0.getContext(), R.anim.push_right_out);
                  // Flip!
                 vf.showNext();
            }
            break;
        }

Ответы [ 2 ]

2 голосов
/ 16 апреля 2012
gridview.setOnTouchListener(new OnTouchListener(){
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return detector.onTouchEvent(event);
    }
});
0 голосов
/ 28 сентября 2011

У меня была такая же проблема с ViewFlipper и ScrollViews. Попробуйте добавить onTouchListener в ваш GridView, и он должен работать.

...