Android TextView with scroll bar, and ScrollView usage (temporarily feel scrollview sliding speed relatively fast)

Source: Internet
Author: User

Originally wanted to do a display text message, when the text is many when the height of the view can not exceed a fixed value, when the text is very small when the height of the view is less than that fixed value, according to the view height display. Because ScrollView no maxheight, unable to meet the demand, had to find another way.

The view itself can be set scrollbar, so it doesn't have to rely on ScrollView. TextView has a property maxline, so that it satisfies the demand, as long as the setting of a textview with ScrollBar, and then set Maxline it can be.

<TextView Android:id="@+id/text_view"Android:layout_width="fill_parent"Android:layout_height="wrap_content"Android:singleline="false"Android:maxlines="Ten"Android:scrollbars="Vertical"/>

You also need to set the TextView in the code to scroll.

    TextView TextView = (TextView) Findviewbyid (R.id.text_view);       Textview.setmovementmethod (Scrollingmovementmethod.getinstance ());  

If you use ScrollView, the code is as follows

<ScrollView android:layout_width="745dip"Android:layout_height="520dip"Android:id="@+id/mbtnre2"Android:layout_margintop="30dip"Android:layout_marginleft="30dip"Android:fadingedge="None"> <TextView android:layout_width="fill_parent"Android:layout_height="fill_parent"Android:id="@+id/mtxtcontent"android:textsize="25SP"Android:textcolor="#000000"Android:fadingedge="None"/></scrollview>

ScrollView can adjust the sliding speed, the realization of their own scrollview

FastSlow Slide ScrollView*@author Peasant Uncle*     */ Public classSlowscrollview extends ScrollView { PublicSlowscrollview (context context, AttributeSet attrs,intDefstyle)        {Super (context, attrs, Defstyle); }            PublicSlowscrollview (Context context, AttributeSet Attrs) {Super (context, attrs); }            PublicSlowscrollview (Context context) {super (context); }           /** * Sliding events*/@Override Public voidFlingintvelocityy) {super.fling (Velocityy/4); }    }

Android TextView with scroll bar, and ScrollView usage (temporarily feel scrollview sliding speed relatively fast)

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.