Android Basic Control Learning-----ScrollView

Source: Internet
Author: User

Explanation of ScrollView (scroll bar):

First, for ScrollView scroll bar is still very good understanding, a total of two kinds of horizontal and vertical, ScrollView and Horizontalscrollview, this inside do not know what to write, say a few ways it

Scrollview.fullscroll (ScrollView.FOCUS.DOWN): Back to the lower part

Scrollview.fullscroll (ScrollView.FOCUS.UP): Back to Top

Scrollview.setverticalsrcollbarenabled (FALSE): Hides the slider (as if the setting is useless)

Android:scrollbarthumbvertical: Set a picture that scrolls vertically (as if it doesn't work)

Android:scrollbarthumbhorizontal: Set a picture that scrolls horizontally (as if it doesn't work)

Android:srollbars = "None" hides the slider (as if the setting is useless)

If we want to control the sliding speed of the slider we need to inherit the method of ScrollView replication public void Fling (int velocityy), this person feels separate summary scrollview nothing to say, first of all.

Two. Simple to use

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">    <ButtonAndroid:id= "@+id/btn1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Back to Top"/>    <ButtonAndroid:id= "@+id/btn2"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_margintop= "10DP"Android:text= "Back to bottom"/>   <ScrollViewAndroid:id= "@+id/sv"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content">       <TextViewAndroid:id= "@+id/tv1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:scrollbarthumbvertical= "@mipmap/ic_launcher"Android:text= "haha"/>   </ScrollView></LinearLayout>

Java code

 PackageCom.example.test3;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.ScrollView;ImportAndroid.widget.TextView; Public classMainactivityextendsActivityImplementsview.onclicklistener{PrivateTextView TextView; PrivateScrollView ScrollView; PrivateButton btn1; PrivateButton btn2; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); TextView=(TextView) Findviewbyid (R.ID.TV1); ScrollView=(ScrollView) Findviewbyid (R.ID.SV); BTN1=(Button) Findviewbyid (R.ID.BTN1); BTN2=(Button) Findviewbyid (R.ID.BTN2); Btn1.setonclicklistener ( This); Btn2.setonclicklistener ( This); StringBuffer SB=NewStringBuffer ();  for(inti = 0;i < 100;i++) {sb.append ("Hehe" + i + "\ n");    } textview.settext (Sb.tostring ()); } @Override Public voidOnClick (view view) {Switch(View.getid ()) { Caser.id.btn1:{Scrollview.fullscroll (SCROLLVIEW.FOCUS_UP);  Break; }             Caser.id.btn2:{Scrollview.fullscroll (Scrollview.focus_down);  Break; }        }    }}

:

Android Basic Control Learning-----ScrollView

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.