所以,我已经遵循了这个特定的线程(如何停止在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)