我是 Android 中的新手,正在使用鳍状肢,我想在顶部添加图像,并且希望对鳍状体没有影响,而身体的其余部分在鳍状体上工作,我面临这个问题,即应用程序停止工作代码和 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;
}
}