ScrollView of common Android components

Source: Internet
Author: User

ScrollView can implement scrolling view in Android, mobile screen size is limited, when the display of more content, scrolling view comes in handy.

This example is mainly generated from the layout file view, just to demonstrate the use of ScrollView, without considering the overall aesthetic effect. Overall, the vertical layout is used to add a TextView component to the first line of the vertical layout, the second line is a scrollview, the vertical layout is added internally, and the third row joins a TextView component.

Using ScrollView in a layout file is generally a way to add a layout to the ScrollView node, as shown below, and ScrollView can also be used as the root node.

<scrollview ... >

<linearlayout ...>

...

</linearlayout>

</scrollview>

The first is the layout file:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"     xmlns: tools= "Http://schemas.android.com/tools"     android:id= "@+id/linearlayout1"      android:layout_width= "Match_parent"     android:layout_height= "Match_parent"     android:orientation= "vertical"     tools:context= "main.test_ ScrollView. Mainactivity " >    <TextView         Android:id= "@+id/textview1"         android:layout_width= "Fill_parent"         android:layout_height= "100SP"          android:background= "#ff0000ff"         android: Textcolor= "#ffffffff"         android:text= "@string/tv1"          android:gravity= "Center"/>    <scrollview          android:id= "@+id/scrollview"         android: Layout_width= "Wrap_content"         android:layout_height= "200DP" >        <LinearLayout             android:id= "@+id/linearlayout2"             android:layout_width= "Fill_parent"             android:layout_height= "Wrap_content"             android:orientation= "Vertical" >           < Progressbar               android: Id= "@+id/progressbar1"   &nbSp;            style= "? android:attr/ Progressbarstylelarge "                android:layout_width= "Wrap_content"                 android:layout_height= "Wrap_content"  />            <ProgressBar                android:id= "@+id/progressbar2"                 style= "Android:attr/progressbarstylelarge"                 android:layout_width= "Wrap_content"                 android:layout_height= " Wrap_content " />           <View                 android:id= "@+id/view1"                 android:layout_width= "Wrap_content"                 android:layout_height= "100SP"                 android:background= "#ff0"  />            <ProgressBar                android:id= "@+id/progressBar3"                 style= "? android:attr/ Progressbarstylelarge "                android:layout_width= "Wrap_content" &Nbsp;              android:layout_height= "Wrap_content"  />           <progressbar                android:id= "@+id/ PROGRESSBAR4 "               style=" ? android:attr/progressbarstylelarge "                android:layout_width= "Wrap_content"                 android:layout_height= "Wrap_content"  />            <View                 android:id= "@+id/view2"              &nbsP;  android:layout_width= "Wrap_content"                 android:layout_height= "100SP"                 android:background= "#f00"  />            <!--  Customize a view component display  -->            <ProgressBar                android:id= "@+id/progressbar5"                 style= "Android:attr/progressbarstylelarge"                 android:layout_width= "Wrap_content"                android:layout_ height= "Wrap_content"  />           <progressbar                android:id= "@+id/progressbar6"                 style= "? android:attr/ Progressbarstylelarge "                android:layout_width= "Wrap_content"                 android:layout_height= "Wrap_content"  />        </LinearLayout>     </ScrollView>    < Textview        android:id= "@+id/textview2"          android:layout_width= "Fill_parent"          android:layout_height= "100SP"     &nbSp;   android:background= "#ff0000ff"         android: gravity= "center"         android:textcolor= "#ffffffff"          android:text= "@string/tv2"  />        </LinearLayout>

Next is the Strings.xml file:

<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >test_scrollview</ string> <string name= "TV1" > Upper border </string> <string name= "Action_settings" >settings</string > <string name= "TV2" > Lower border </string></resources>

Again is the Android source code file (just referencing the layout file, no other changes):

Package Main.test_scrollview;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;public class Mainactivity extends Actionbaractivity {@Override protected void onCreate (Bundle savedinstancestate) {s        Uper.oncreate (savedinstancestate);          Setcontentview (R.layout.activity_main); }}

Finally, the test results are as follows:

ScrollView of common Android components

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.