对不起我的英语不好。当图片填满屏幕时,我想做的就是可以用来滚动。为此,请使用ViewFlipper。但它不起作用。是全屏显示图像的类。我究竟做错了什么?
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>
最佳答案
您的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>
关于java - 不起作用ViewFlipper,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26046907/