I want to show a Profile screen for my users.
It must have three views (2 Buttons
and a ImageView
) and a ListView
to show the content made by that user.
However, I don't want the ListView
to scroll. Instead, I want it to be as big as needed, and to put all my views inside a ScrollView
, so the three first views scroll out with the ListView
. This, of course, does not work as intended.
All my three items are inside a LinearLayout
. I thought of making them the first item in the ListView
, but this leads to them being selectable as the first item, and having to do some unneeded coding.
Is there a way to do this the easy way or will I have to stick with making the Layout the first item in my ListView?
if you have to show limited number of items in list view and want to stop list view from scrolling then you must keep listview height greater then the items total height.
for example you want to show 3 items. (height of row is 30). then items total height becomes 3 x 30dp = 90dp,
so now you have to set listview height greater then 90. e.g: 100dp. so now your listview will not scroll in any case.
I would add a
View
with invisible background on top ofListView
. Set aView.OnTouchListener()
to it. And consume the event by returningtrue
inonTouch()
method ofView.OnTouchListener()
.When you want the list to be scrolling back again, remove the touch listener set on the transparent
View
with the following instruction:
new_size is a variable that you will calculate according to the number of elements of your list, for example:
I think the best way would be to put the 2 buttons and the image view in a LinearLayout (or any layout that suits your need) and add this layout as the list header using the addHeaderView method:
http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View)
I found a very simple solution for this. Just get the adapter of the listview and calculate its size when all items are shown. The advantage is that this solution also works inside a ScrollView.
Example:
Call this function passing over your ListView object:
The function shown above is a modidication of a post in: Disable scrolling in listview
Please note to call this function after you have set the adapter to the listview. If the size of entries in the adapter has changed, you need to call this function as well.
Adding them to the ListView as first Item seems like a pretty good solution.
To make the View unselectable just get the view and
.setClickable(false)
.