如何在android中制作自定义图库视图
我正在尝试创建自定义图库视图。或者也许我不明白我应该在这里做什么。我需要覆盖 Gallery 类的 onFling() 方法,但我不知道如何执行此操作,因为我的主类必须从 Activity< 扩展/强>。
我尝试创建一个名为 CustomGallery 的类来扩展 Gallery,但是如果我尝试运行该应用程序,我会强制关闭。
如何重写 Gallery View 的 onFling() 方法?
谢谢!
编辑
我正在尝试下面克里斯蒂安的解决方案,但是,这个类到处都有错误。显然我做错了。建议?
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Gallery;
public class CustomGallery extends Gallery
{
public CustomGallery(Context context)
{
super(context);
}
@Override
public Gallery(Context context)
{
this(context, null);
}
@Override
public Gallery(Context context, AttributeSet attrs)
{
this(context, attrs, R.attr.galleryStyle);
}
@Override
public Gallery(Context context, AttributeSet attrs, int defStyle)
{
//
}
}
编辑2
好的,这已经成功了,谢谢克里斯蒂安!
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Gallery;
public class CustomGallery extends Gallery
{
public CustomGallery(Context context, AttributeSet attrs)
{
super(context, attrs);
}
}
I am trying to create a custom Gallery view. Or maybe I'm not understanding what I'm supposed to do here. I need to overwrite the onFling() method of the Gallery class, but I do not see how I can do this as my main class must extend from Activity.
I have tried making a class called CustomGallery that extends Gallery, but If I try and run the app I get a force close.
How does one overwrite the onFling() method for a Gallery View?
Thanks!
EDIT
I am attempting Christian's solution below however, this class has errors all over it. Clearly I am doing this wrong. Suggestions?
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Gallery;
public class CustomGallery extends Gallery
{
public CustomGallery(Context context)
{
super(context);
}
@Override
public Gallery(Context context)
{
this(context, null);
}
@Override
public Gallery(Context context, AttributeSet attrs)
{
this(context, attrs, R.attr.galleryStyle);
}
@Override
public Gallery(Context context, AttributeSet attrs, int defStyle)
{
//
}
}
EDIT 2
ok this got it working, thx Christian!
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Gallery;
public class CustomGallery extends Gallery
{
public CustomGallery(Context context, AttributeSet attrs)
{
super(context, attrs);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CustomGallery
,XD)就像使用
Gallery
一样使用它:确保重写构造函数方法:
CustomGallery
, XD)Just use it like if you were using a
Gallery
:Make sure to override the constructor methods: