英文:
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.
专注分享java语言的经验与见解,让所有开发者获益!
评论