public class FullScreenImage extends Activity implements OnTouchListener{
private ViewFlipper flipper = null;
private float fromPosition;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_screen);
Intent intent = getIntent();
long imageId = intent.getExtras().getLong(FullScreenImage.class.getName());
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
flipper = (ViewFlipper) findViewById(R.id.fullImage);
flipper.setOnTouchListener(this);
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setLayoutParams( new ViewFlipper.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
imageView.setImageResource((int) imageId);
}
public boolean onTouch(View view, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
fromPosition = event.getX();
break;
case MotionEvent.ACTION_UP:
float toPosition = event.getX();
if (fromPosition > toPosition)
flipper.showNext();
else if (fromPosition < toPosition)
flipper.showPrevious();
default:
break;
}
return true;
}
}
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/fullImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ViewFlipper>
</LinearLayout>
答案 0 :(得分:1)
你的XML在脚蹼中只有一个成员。想法是有两个或项目,鳍状肢将在它们之间改变。将这样的另一个图像添加到您的鳍状肢
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/fullImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ViewFlipper>