我使用过Flipper。我们通常在翻转标签中添加布局。如下
<flipper>
<LinearLayout1>
<LinearLayout2>
</flipper>
在我的程序中,有三个活动我想在鳍状肢中显示(它应该一个接一个地翻转。)
每个活动单独执行一些任务。
当我将该布局文件添加到鳍状板标签中时。如下所示,
(这是我的主要xml文件)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ViewFlipper
android:id="@+id/ViewFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" >
<include
android:id="@+id/screenxyzf"
layout="@layout/screenxyz" />
<include
android:id="@+id/screenabcf"
layout="@layout/screenabc" />
<include
android:id="@+id/activity_mainf"
layout="@layout/activity_main" />
</ViewFlipper>
</LinearLayout>
//我的Java代码......
package com.example.exampledemo3;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;
public class Swipe extends Activity {
ViewFlipper flipper;
float lastX;
View.OnTouchListener gestureListener;
LinearLayout chapterMain,chapterAbc,chapterXyz;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.swipe);
flipper = (ViewFlipper) findViewById(R.id.ViewFlipper);
/*chapterMain=(LinearLayout) findViewById(R.id.activity_mainf);
chapterAbc=(LinearLayout) findViewById(R.id.screenabcf);
chapterXyz=(LinearLayout) findViewById(R.id.screenxyzf);*/
flipper.setDisplayedChild(R.id.activity_mainf);
flipper.setDisplayedChild(R.id.screenabcf);
flipper.setDisplayedChild(R.id.screenxyzf);
}
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
if (flipper.getDisplayedChild() == 0)
break;
flipper.setInAnimation(this, R.anim.in_from_left);
flipper.setOutAnimation(this, R.anim.out_to_right);
flipper.showNext();
}
if (lastX > currentX) {
if (flipper.getDisplayedChild() == 1)
break;
flipper.setInAnimation(this, R.anim.in_from_right);
flipper.setOutAnimation(this, R.anim.out_to_left);
flipper.showPrevious();
}
break;
}
}
return false;
}
}
现在在我的代码中,脚蹼工作正常,但我想在Flipper中显示的活动不起作用(Activites不工作,意味着listview没有加载数据,按钮,textview是可见的,但不支持任何事件)。
有谁能告诉我该怎么做..?
答案 0 :(得分:0)
android:id
,否则这些将无用。看看这个:
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ViewFlipper"
android:background="#ffffff" >
<include layout="@layout/screenxyz"
android:id="@+id/xyzView" />
<include layout="@layout/activity_main"
android:id="@+id/mainView" />
<include layout="@layout/screenabc"
android:id="@+id/abcView" />
</ViewFlipper>