简体   繁体   中英

How to create a vertically scrollable list where some (not all) elements are horizontally scrollable cards?

I am working on an Android app and have recently been given a task where I need to update an existing ListView, containing search results, to include a horizontally scrollable list of cards at the first position. Each card should be tappable, but I should still be able to vertically scroll through the entire list.

I think I can implement this by just using a HorizontalScrollView as a custom view for the first item in the list. However, is there a way to keep the horizontal list and the existing ListView separate, while maintaining the ability to vertically scroll?

I'm not entirely sure what you mean by keeping the horizontal list and ListView separate, but I think you can achieve what you want by adding the HorizontalScrollView as a HeaderView to the ListView, as described here:

https://stackoverflow.com/a/14098678/4166923

What about adding a HeaderView to the ListView?

http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View,%20java.lang.Object,%20boolean)

ListView list = (ListView) getView().findViewById(R.id.my_list);
LayoutInflater inflater = getActivity().getLayoutInflater();
ViewGroup header =(ViewGroup)inflater.inflate(R.layout.header, list, false);
HorizontalScrollView sv = (HorizontalScrollView)header.findViewById(R.id.scroll_list);
sv.setAdapter(adapter);
list.addHeaderView(header, null, false);

在Android的垂直列表视图中检查此示例水平列表视图,并通过放置某些条件,也可以在垂直列表视图中添加其他卡

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM