我有一个带有几个全屏图像的画廊.我想将fling手势限制为一次只推进一个图像(如HTC Gallery应用程序).什么是正确/最简单的方法来实现这一目标?
所以,我已经遵循了这个特定的线程(如何停止在Gallery Widget中滚动?)但我无法让它正常工作.
我创建了一个扩展Gallery的自定义MyGallery类.我在上面的链接中添加了代码...我应该添加<com.example.mygallery到XML文件中吗?如果是这样,我还要将导入添加到java文件中,还是因为XML文件而不需要?我很困惑.
我想简单地让画廊每次移动一张图像.
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/carlot_background"
>
<com.gallerytest.mygallery
android:id="@+id/thisgallery"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
mygallery.java:
package com.gallerytest;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
public class mygallery extends Gallery {
public mygallery(Context ctx, AttributeSet attrSet) {
super(ctx);
// TODO Auto-generated constructor stub
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ …Run Code Online (Sandbox Code Playgroud) 我对Android动画和手势比较陌生.
我有15张想要滑动的图像.屏幕上一次只显示一个图像,当我在第一张图像上滑动L-> R时,第二张图像显示,依此类推 - 就像幻灯片一样.我查看了Android Gallery教程,但我不希望显示缩略图.我的理解是使用ImageView并不断更改图像.这是正确的方法还是有更好的方法?