Scrolling Issues Using ListView Inside ScrollView

Here the script is conceptual (excluding linearlayouts)

ScrollView Button Checkboxes Spinner ListView (full-size, non-scrolling) AdMob advert 

i.e. a scroll bar that has a UI filter at the top and then results, but the ad should always remain visible, and when scrolling, the filter user interface should scroll, leaving maximum space for the results.

I know there are problems with the ListView inside the ScrollView, although for me it works well in many ways (I fix the length of the ListView to stop it from folding). Thus, the screen scrolls beautifully, the ad remains at the bottom, and it looks good.

But the problem that I see is inexplicable when the activity opens, ScrollView scrolls a bit, so the ListView is at the top of the screen. I assume this is the default behavior, so I started trying to get the ScrollView position scroll at the top, but I tried various methods and didn't see any effect:

 scrollview.scrollTo(0, 1000/-1000); scrollview.smoothScrollBy(0, 1000/-1000); scrollview.fullScroll(View.FOCUS_UP); 

Is there a way to get ScrollView to start from the scroll position at the top?

If not, how can I get an ad that doesn't scroll down, but a filter user interface that always scrolls from the top? Using a ListView seems redundant since I don't need scrolling, but it has many advantages, so it would be nice to avoid starting from scratch and doing everything yourself.

+6
android
source share
6 answers

Why are you using a list if you are not scrolling? Why can't you just use line out or something more appropriate for this situation? You mention a filter, you can easily collapse your own filter, because apparently you have only a few items in your list.

0
source share

Use the following method and enjoy!

  private void setListViewScrollable(final ListView list) { list.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { listViewTouchAction = event.getAction(); if (listViewTouchAction == MotionEvent.ACTION_MOVE) { list.scrollBy(0, 1); } return false; } }); list.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (listViewTouchAction == MotionEvent.ACTION_MOVE) { list.scrollBy(0, -1); } } }); } 

listViewTouchAction is a global integer value. If you can replace the string

 list.scrollBy(0, 1); 

with something else, please share it with us.

+1
source share

Use something else that ListView, you can dynamically generate linearLayouts to show the desired data. You should never use listview inside scrollView, it doesn’t work for the simple reason when you scroll that you need to scroll, view the list or view the scroll. Several people from Google said they should not do this.

0
source share

I ran into a ScrollView scroll problem that scrolls a bit, the solution was to post a runnable which called the animateTo (0,0) method to get a list to scroll up. I found that this only works with anitmatTo (0,0) scrollTo (0,0), doesn't seem to work.

Something along the lines of:

 mListView.post(new Runnable(){ public void run() { mListView.animateScrollTo(0,0) }); 

Now, as already mentioned, you do not have to do the entire ListView inside the ScrollView, but this may be the fix for the problem you had.

0
source share

I have:

 ScrollView TextView Button TextView ListView 

and this work is good for me:

 scrollView.smoothScrollBy(0, 0); 

without this view, it starts at the list position, after which it starts at the top

0
source share

The solution to this problem is to make the request focus on the object at the top of the ScrollView. For example, you can use the table layout by wrapping a button and requesting focus on the table layout (if you focus the button, it will change its color).

 // onCreate method TableLayout tablelayout = (TableLayout) findViewById(R.id.tablelayout); tablelayout.setFocusableInTouchMode(true); tablelayout.requestFocus(); 
-one
source share

All Articles