2013-02-06 46 views
0

我是新的Android工作在脚蹼上,我wana在顶部添加图像,并希望对脚蹼没有影响,其余的身体工作在脚蹼上,我面临的问题是应用程序有停止工作的代码和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; 


    } 
} 
+0

LogCat上是否有任何错误? – NaviRamyle

回答

0

只是好奇你为什么使用ViewFlipper而不是处理触摸手势的组件。你有足够:

这两个将处理您目前没有处理的手势,移动视图以提示用户,他可以滑动,...