【问题标题】:Viewflipper not working with ScrollViewViewflipper 不适用于 ScrollView
【发布时间】:2012-02-10 08:44:30
【问题描述】:

我正在制作一个 android 应用程序,我试图在其中使用 viewflipper 在不同的视图之间滑动。我从here 那里得到了帮助。我尝试使用代码进行试验,但我现在遇到了问题。我的一个布局中有一个滚动视图,因此 viewflipper 没有在视图之间切换。谁能帮帮我吗?这是我的 xml 布局代码,三个屏幕可以滑动:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <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:background="#ffffff"
            android:orientation="vertical" >


            <!-- <ScrollView -->
            <!-- android:id="@+id/flotest" -->
            <!-- android:layout_width="match_parent" -->
            <!-- android:layout_height="match_parent" -->
            <!-- android:background="#FFFFFF" > -->


            <!-- <LinearLayout -->
            <!-- android:id="@+id/LR1" -->
            <!-- android:layout_width="match_parent" -->
            <!-- android:layout_height="match_parent" > -->


                    <TextView
                        android:id="@+id/floText"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:text="@string/flo_garbage"
                        android:textColor="#000000" />
<!--                 </LinearLayout> -->
<!--             </ScrollView> -->
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/rl1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:text="@string/current_city"
                    android:textColor="#000000" />

                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:src="@drawable/disclosure" />
            </RelativeLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/floText"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="FRIENDS PAGE"
                android:textColor="#000000"
                android:textSize="50dip" />
        </LinearLayout>
    </ViewFlipper>

</LinearLayout>

上面的代码工作得很好,但如果我取消注释滚动视图部分,滑动不起作用。这是我的活动代码:

   public class main extends Activity implements OnTouchListener {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            layMain = (LinearLayout) findViewById(R.id.layout_main);
            layMain.setOnTouchListener((OnTouchListener) this);

        }

        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
                float currentX = arg1.getX();

                // going backwards: pushing stuff to the right
                if (downXValue < currentX) {
                    ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                    vf.setInAnimation(AnimationUtils.loadAnimation(this,
                            R.anim.push_left_in));
                    vf.setOutAnimation(AnimationUtils.loadAnimation(this,
                            R.anim.push_right_out));
                    if (screenmiddle) {
                        vf.showNext();
                        screenleft = true;
                        screenmiddle = false;
                        screenright = false;
                    } else if (screenright) {
                        vf.showNext();
                        screenleft = false;
                        screenmiddle = true;
                        screenright = false;
                    }
                }

                // going forwards: pushing stuff to the left
                if (downXValue > currentX) {

                    ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);

                    vf.setInAnimation(AnimationUtils.loadAnimation(this,
                            R.anim.push_right_in));
                    vf.setOutAnimation(AnimationUtils.loadAnimation(this,
                            R.anim.push_left_out));
                    if (screenleft) {
                        vf.showPrevious();
                        screenleft = false;
                        screenmiddle = true;
                        screenright = false;
                    } else if (screenmiddle) {
                        vf.showPrevious();
                        screenleft = false;
                        screenmiddle = false;
                        screenright = true;
                    }
                }
                break;
            }
            }

            // if you return false, these actions will not be recorded
            return true;
        }


    }

我知道这是thisthis 中的常见问题,但我找不到任何解决方案。

【问题讨论】:

    标签: android animation scrollview viewflipper


    【解决方案1】:

    与其使用滚动的 TextView,不如使用 ListView,因为 ListView 自动启用了滚动功能。所以上面相同的代码在 ListView 而不是 TextView 上工作得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多