Resolves automatic scrolling after controls in ScrollView are disabled in Android

Source: Internet
Author: User

Ext.: http://my.oschina.net/cjk035/blog/127445

Recently doing a project, above is a linearlayout layout, the following is a Baidu map of the Mapview control, Mapview control of the height of the larger, resulting in the entire page content beyond the screen display area, so on the outside set a ScrollView, But new problems arise, each time you enter the page, because the map loading caused scrollview always automatically scroll to the bottom, the above LinearLayout area only shows the following part, in order to solve this problem I used the scrollview. Fling (0), Scrollview.scrollto (0,0); but none of them worked, but the seemingly simple problem became so tight that it took a long time to find the best solution:

Override the following method in ScrollView and set its return value to 0.

@Override
protected int Computescrolldeltatogetchildrectonscreen (rect rect) {

return 0;
}

Ext.: http://blog.csdn.net/icyfox_bupt/article/details/15026299

Problem:

Recently writing a program interface, there is a scrollview, where there is a piece of content that needs to be loaded online.

When the content is loaded, the length of the content in the ScrollView changes, and ScrollView automatically rolls down as shown:

The scrolling experience is particularly bad, so avoid this situation. That is, whatever the content of the ScrollView, keep it to the top.

Workaround:

Just write the structure of my XML file briefly:

[HTML]View PlainCopy
  1. <ScrollView
  2. android:id="@+id/scrollview1"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:layout_alignparentleft="true"
  6. android:layout_below="@+id/linearlayout2"
  7. android:background="@drawable/repeat_bg"
  8. android:paddingbottom="5DP" >
  9. <linearlayout
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:orientation="vertical"
  13. android:paddingleft="10DP"
  14. android:paddingright="10DP"
  15. android:focusable="true"
  16. android:focusableintouchmode="true"
  17. android:paddingtop="15DP" >
  18. <!--above these two lines is control ScrollView
  19. android:focusable="true"
  20. android:focusableintouchmode="true"
  21. Not automatic key!!-->
  22. <linearlayout
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. android:orientation="vertical" >
  26. <ListView
  27. android:id="@+id/lv_gc"
  28. android:layout_margintop="5DP"
  29. android:layout_width="match_parent"
  30. android:layout_height="20DP"
  31. android:background="#aaffffff"
  32. android:divider="#666"
  33. android:scrollbars="none|vertical" >
  34. </ListView>
  35. </linearlayout>
  36. </linearlayout>
  37. </ScrollView>


As the above code, the first content in my ScrollView is LinearLayout, and below is a linearlayout wrapped listview.listview that is variable in length.

Add the code to the LinearLayout:

[HTML]View PlainCopy
    1. android:focusable="true"
    2. Android:focusableintouchmode="true"

Problems can be solved, welcome to exchange.

Resolves automatic scrolling after controls in ScrollView are disabled in Android

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.