The section with ScrollView as the root cannot display its contained page content from the top. The scrollview page

Source: Internet
Author: User

The section with ScrollView as the root cannot display its contained page content from the top. The scrollview page


The departments that use ScrollView as the root cannot display the page content contained in it from the top. This is my biggest headache. Many conflicts are solved one by one. In the end, I encountered such a problem and searched the internet, but I don't know what keywords to use! The online resources will find several Forum conversations about this aspect. This is also a problem for the friends who have encountered this problem. Let me explain it now!

Problem:

The layout is basically like this:

<? Xml version = "1.0" encoding = "UTF-8"?> <ScrollView xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/shortMovieScrollView" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: background = "# fff"> <RelativeLayout android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: background = "# f8f8f8"> <include android: id = "@ + id/lay_shortMovie_titleBar" layout = "@ layout/title _ Public_item1 "/> <TextView android: id =" @ + id/tvLine_1 "android: layout_width =" fill_parent "android: layout_height =" 1dp "android: layout_alignBottom = "@ + id/lay_shortMovie_titleBar" android: background = "# C8C7CC"/> <RelativeLayout android: id = "@ + id/layout_filterBar" android: layout_width = "fill_parent" android: layout_height = "45dp" android: layout_below = "@ + id/lay_shortMovie_titleBar" android: background = "# f8f8 F8 "> <LinearLayout android: layout_width =" fill_parent "android: layout_height =" 45dp "> <TextView android: id =" @ + id/TV _shortMovie_Selectleft "android: layout_width = "fill_parent" android: layout_height = "45dip" android: layout_weight = "1" android: background = "@ drawable/btn_bg_color_selector" android: drawableLeft = "@ drawable/icon_filter_teaching" android: gravity = "center_vertical" android: paddingLeft = "30dp" Droid: text = "screening micro-Movies" android: textColor = "#8f8f95" android: textSize = "16sp"/> <ImageView android: id = "@ + id/img_line_portrait" android: layout_width = "0.5dp" android: layout_height = "fill_parent" android: background = "# C8C7CC"/> <TextView android: id = "@ + id/TV _shortMovie_Selectright" android: layout_width = "fill_parent" android: layout_height = "45dip" android: layout_weight = "1" android: background = "@ drawable/btn_bg _ Color_selector "android: drawableLeft =" @ drawable/img_icon_random_filter "android: gravity =" center_vertical "android: paddingLeft =" 30dip "android: text =" discover micro movies "android: textColor = "#8f8f95" android: textSize = "16sp"/> </LinearLayout> </RelativeLayout> <TextView android: id = "@ + id/tvLine_2" android: layout_width = "fill_parent" android: layout_height = "1dp" android: layout_below = "@ + id/layout_filterBar" android: bac Kground = "# C8C7CC"/> <android. support. v4.view. viewPager android: id = "@ + id/shortMovie_viewpager" android: layout_marginTop = "0.5dp" android: layout_width = "fill_parent" android: layout_height = "180dip" android: layout_below = "@ + id/tvLine_2" android: background = "# fff"/> <LinearLayout android: id = "@ + id/shortMovie_viewGroup" android: layout_width = "fill_parent" android: layout_height = "35dip" android: layout_alignPa Export right = "true" android: layout_alignBottom = "@ + id/shortMovie_viewpager" android: background = "@ drawable/ic_transparent_content_title" android: gravity = "center_vertical | right" android: orientation = "horizontal" android: paddingRight = "10dp"> </LinearLayout> <TextView android: id = "@ + id/filmName" android: layout_width = "wrap_content" android: layout_height = "35dp" android: layout_alignBottom = "@ + id/shortMovie_vie WGroup "android: layout_alignParentLeft =" true "android: gravity =" center_vertical "android: text =" willingness of a dog "android: textColor =" # fff "android: textSize = "16sp"/> <! -- Recommended movie for Masterpiece --> <ImageView android: id = "@ + id/img_line_1" android: layout_width = "3dip" android: layout_height = "30dip" android: layout_below = "@ + id/shortMovie_viewGroup" android: layout_marginLeft = "15dip" android: layout_marginTop = "15dip" android: background = "# f1a73c"/> <TextView android: id = "@ + id/name_movieHeadLine_1" android: layout_width = "wrap_content" android: layout_height = "30dip" android: layout_below = "@ + id /Define movie_viewgroup "android: layout_marginLeft =" 10dip "android: layout_marginTop =" 15dip "android: layout_toRightOf =" @ + id/img_line_1 "android: gravity =" center_vertical "android: text = "" android: textSize = "16sp"/> <GridView android: id = "@ + id/item1_gridView_top" android: layout_width = "fill_parent" android: layout_height = "350dip" android: layout_below = "@ + id/img_line_1" android: layout_marginTop = "5dip" Droid: cacheColorHint = "# ffffff" android: listSelector = "# ffffff" android: horizontalSpacing = "5dip" android: transcriptMode = "disabled" android: numColumns = "3" android: scrollbars = "none" android: verticalSpacing = "20dip"/> <! -- Domestic movie --> <ImageView android: id = "@ + id/img_line_2" android: layout_width = "3dip" android: layout_height = "30dip" android: layout_below = "@ + id/item1_gridView_top" android: layout_marginLeft = "15dip" android: layout_marginTop = "15dip" android: background = "# f1a73c"/> <TextView android: id = "@ + id/name_movieHeadLine_2" android: layout_width = "wrap_content" android: layout_height = "30dip" android: layout_below = "@ + id/ite M1_gridView_top "android: layout_marginLeft =" 10dip "android: layout_marginTop =" 15dip "android: layout_toRightOf =" @ + id/img_line_2 "android: gravity =" center_vertical "android: text = "recommended for domestic works" android: textSize = "16sp"/> <GridView android: id = "@ + id/item2_gridView_top" android: layout_width = "fill_parent" android: layout_height = "350dip" android: layout_below = "@ + id/img_line_2" android: layout_marginTop = "5dip" androi D: cacheColorHint = "# ffffff" android: listSelector = "# ffffff" android: horizontalSpacing = "5dip" android: transcriptMode = "disabled" android: numColumns = "3" android: scrollbars = "none" android: verticalSpacing = "20dip"/> <! -- Foreign movies --> <ImageView android: id = "@ + id/img_line_3" android: layout_width = "3dip" android: layout_height = "30dip" android: layout_below = "@ + id/item2_gridView_top" android: layout_marginLeft = "15dip" android: layout_marginTop = "15dip" android: background = "# f1a73c"/> <TextView android: id = "@ + id/name_movieHeadLine_3" android: layout_width = "wrap_content" android: layout_height = "30dip" android: layout_below = "@ + id/item2_gridView_top" android: layout_marginLeft = "10dip" android: layout_marginTop = "15dip" android: layout_toRightOf = "@ + id/img_line_3" android: gravity = "center_vertical" android: text = "Recommended works abroad" android: textSize = "16sp"/> <GridView android: id = "@ + id/item3_gridView_top" android: layout_width = "fill_parent" android: layout_height = "350dip" android: layout_below = "@ + id/img_line_3" android: layout_marginTop = "5dip" android: cacheColorHint = "# ffffff" android: listSelector = "# ffffff" android: horizontalSpacing = "5dip" android: transcriptMode = "disabled" android: numColumns = "3" android: scrollbars = "none" android: verticalSpacing = "20dip"/> </RelativeLayout> </ScrollView>

The root board is ScrollView, and a TitleBar title is nested in the root board. The following is a ViewPager, and the following are three GridView in sequence.

The layout is like this. After I run it, the page display result is not displayed from the position y = 0 of ScrollView. That is, all content on the page is displayed at the center of the ScrollView instead of at the top of the page;

Solution: Some people say how to use it:

mScrollView.smoothScrollTo(0, 0);
Or
mScrollView.scrollTo(0, 0);
However, it cannot be used after my tests. One existing method can solve the problem: use the control View and layout at the top of the ScrollView in the layout, and use these lines of code to get the focus; as follows:
view.setFocusable(true);view.setFocusableInTouchMode(true);view.requestFocus();





How to obtain the scrollview rolling distance in real time?

In fact, you can achieve this by creating a layout with the same level as scrollview and the central tab card selection, and setting it to hide the View at the beginning. GONE: When scrollview is rolled to the central position, it is OK to display it. When it is smaller than the central position, it is hidden. I did that, but I was not a scrollview, but a ListView.

In android programming, how does one implement Page scrolling using ScrollView? How to Implement

1L positive solution. It is to wrap a layer of ScrollView outside all the controls in your current xml, so that all the displayed content in the ScrollView can be viewed in a rolling manner.

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.