ListView and LineraLayout under one ScrollBar
-
20-09-2019 - |
Question
I want to create the following layout:
- Section '1' is a
LinearLayout
which contains anImageView
and aTextView
- Section '2' is a
ListView
with customized row layouts.
I want to place both components under a single vertical ScrollBar
, meaning I don't want the ScrollBar
only for the ListView
. Currently I'm achieving the following layout through placing things in a TableView
but I want functionality like ListView
items.
Solution
You can programmatically add 'Section 1' as a header view to the ListView using ListView.addHeaderView(View v)
. See docs here.
Example code here:
View headerView = getLayoutInflater().inflate(
R.layout.foo_list_header, null);
mListView = (ListView) findViewById(...);
mListView.addHeaderView(headerView);
setListAdapter(...);
OTHER TIPS
You could make a "Section 1" to be a part of your list. Just add another type for your customized items list, add "section 1" as first element of your list , and your scrollbar will work as you desired.
I think that is the most convenient approach.
Regards!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow