Android 鳍状肢停止工作

Android 鳍状肢停止工作,android,Android,我是Android新手,在flipper上工作,我想在顶部添加图像,不想对flipper和flipper上的其他身体工作产生任何影响,我面临这个问题,应用程序已经停止工作。下面列出了代码和xml .xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width

我是Android新手,在flipper上工作,我想在顶部添加图像,不想对flipper和flipper上的其他身体工作产生任何影响,我面临这个问题,应用程序已经停止工作。下面列出了代码和xml

.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <ViewFlipper
        android:id="@+id/view_flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_margin="6dip" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="this is text 1"
                android:textColor="#00ff00"
                android:textSize="14sp"
                android:textStyle="bold" >
            </TextView>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="this is text 2"
                android:textColor="#00ff00"
                android:textSize="14sp"
                android:textStyle="bold" >
            </TextView>
        </LinearLayout>
    </ViewFlipper>

</RelativeLayout>

.java

package com.test.flipper_example;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.ViewFlipper;

public class Offlipper_example3 extends Activity{
    private ViewFlipper vf;
    private float lastX;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.flipper03);
        vf = (ViewFlipper) findViewById(R.id.view_flipper);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    @Override
    public boolean onTouchEvent(MotionEvent te) {
        switch (te.getAction())
        {
        case MotionEvent.ACTION_DOWN:
        {
        lastX = te.getX();
        break;
        }
        case MotionEvent.ACTION_UP:
        {
        float currentX = te.getX();
        if (lastX < currentX)
        {
        if (vf.getDisplayedChild()==0) break;
        vf.setInAnimation(this, R.anim.slide_left);
        vf.setOutAnimation(this, R.anim.slide_right);
        vf.showNext();
        }
        if (lastX > currentX)
        {
        if (vf.getDisplayedChild()==1) break;
        vf.setInAnimation(this, R.anim.slide_right);
        vf.setOutAnimation(this, R.anim.slide_left);
        vf.showPrevious();
        }
        break;
        }
        }

        return false;


    }
}
package com.test.flipper\u示例;
导入android.os.Bundle;
导入android.app.Activity;
导入android.view.Menu;
导入android.view.MotionEvent;
导入android.widget.ViewFlipper;
Lipper_示例3的公共类扩展了活动{
私有视图翻转器vf;
私人浮动lastX;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.flipper03);
vf=(ViewFlipper)findViewById(R.id.view\u flipper);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.activity\u主菜单);
返回true;
}
@凌驾
公共事件(MotionEvent te){
开关(te.getAction())
{
case MotionEvent.ACTION\u DOWN:
{
lastX=te.getX();
打破
}
case MotionEvent.ACTION\u UP:
{
float currentX=te.getX();
if(lastXcurrentX)
{
如果(vf.getDisplayedChild()==1)中断;
vf.设定无生气(这是右动画幻灯片);
vf.setOutAnimation(这是R.anim.slide_左);
vf.showPrevious();
}
打破
}
}
返回false;
}
}

只是好奇,为什么您要使用ViewFlipper而不是已经处理触摸手势的组件。你有很多:

  • ViewPager(兼容性库)
  • 取景器()

这两个都将处理您当前未处理的手势,移动视图以提示用户可以滑动,

LogCat上是否有任何错误?