如果我不需要可滚动功能,是否有替代 RecyclerView 的选项?

huangapple 未分类评论58阅读模式
英文:

Substitute for RecyclerView if I do not need the scrollable functionality?

问题

New to android java and trying to figure this out. If I want to have an array adapter to display a list of images horizontally, what options do I have other than RecyclerView?

Basically, I am making a Chinese mahjong game. I want to display thumbnails horizontally that needs onClickListener functionality. The screen needs to NOT be scrollable. A LinearLayout doesn't seem to have an arrayadapter.

英文:

New to android java and trying to figure this out. If I want to have an array adapter to display a list of images horizontally, what options do I have other than RecyclerView?

Basically, I am making a Chinese mahjong game. I want to display thumbnails horizontally that needs onClickListener functionality. The screen needs to NOT be scrollable. A LinearLayout doesn't seem to have an arrayadapter.

答案1

得分: 0

没有布局类似于arrayadapter,如果图像数量不会改变,我建议将它们放在您提到的布局内,并分别引用各个图像视图。

或者,如果数量是动态的,我建议使用ListView,但禁用滚动,例如使用以下代码:

listView.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        return (event.getAction() == MotionEvent.ACTION_MOVE);
    }
});
英文:

No Layout has something similar to the arrayadapter, if the amount of images don't change I would suggest putting them inside of a layout as you mentioned and reference the seperate imageviews seperately

Alternatively, if the amount is dynamic I'd suggest using a ListView but disabling scrolling, for example using this:

listView.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {
        return (event.getAction() == MotionEvent.ACTION_MOVE);
    }
});

答案2

得分: 0

你实际上可以使用 RecyclerView 来实现这个(假设你有足够新的版本,尽管它已经支持了几年)。

你只需创建一个水平的 RecyclerView,并将其 android:layout_width 设置为 "wrap_content"。这将导致它填充所有可用的项目,然后根据它们的总宽度调整自身大小。

英文:

You can actually use RecyclerView for this (assuming you have a new enough version, though it's supported this for a couple years now)

You'd just need to create a horizontal RecyclerView and set its android:layout_width to "wrap_content". That will cause it to inflate all of the available items and then size itself to their total width.

huangapple
  • 本文由 发表于 2020年5月3日 17:30:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/61572277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定