articles

Android ScrollView Control

Nitish Kesarwani 2691 02-Jan-2018
ScrollView in Android

Scrollview is used to define the content on the screen. It provides the platform in which content is adjustable according to the content display in a view. ScrollView has several attributes and methods which is helpful in developing the interactive user interface and data.

Attributes

Android: viewport: It defines the content is either filled to the Viewport or not.

Methods 

• arrowScroll(): it provides Up and down arrow view on screen to scroll the content.

computeScroll(): it called by a parent to upgrade their child with maximum(x,y) coordinates for computing the number of scrolled event.

FullScroll(): it can respond to Home/End which means it can move up and down with immediate action.

PageScroll() : It can generate response on PageUp/PageDown keystroke.

ScoreTo() : it can provide a view in which user can move along x-axis and y-axis of a screen.

isViewPort() : it checks whether the viewport is enabled.

Android_Manifest.xml 
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mapsample.msclient009.scrollview">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Main_Activity.xml 
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.mapsample.msclient009.scrollview.MainActivity">


    <ScrollView
        android:id="@+id/SView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <LinearLayout
        android:background="#F0E991"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:padding="20dp"
            android:id="@+id/tv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="20dp"
            android:textColor="#FF0066"
            android:text="RED"/>
              <TextView
                  android:padding="20dp"
                  android:textColor="#199119"
                  android:textSize="20dp"
                  android:text="Green"
                  android:gravity="center"
                  android:id="@+id/tv2"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" />
        <TextView
            android:padding="20dp"
            android:textColor="#0090FF"
            android:textSize="20dp"
            android:text="Blue"
            android:gravity="center"
            android:id="@+id/tv3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <TextView
            android:padding="20dp"
            android:textColor="#000"
            android:textSize="20dp"
            android:text="Black"
            android:gravity="center"
            android:id="@+id/tv4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
                     android:padding="20dp"
                     android:background="#A9DFAD"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:id="@+id/btn"
                     android:text="First"/>
        <Button
            android:padding="20dp"
            android:background="#999989"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btn1"
        android:text="second"/>
        <Button
            android:padding="20dp"
            android:background="#FF90AA"
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Third" />
        <Button
            android:padding="20dp"
            android:background="#11AAFF"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btn3"
            android:text="fourth"/>
        <Button
            android:padding="20dp"
            android:background="#22AA22"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btn4"
            android:text="fifth"/>
    </LinearLayout>
    </ScrollView>
</LinearLayout>

Main_Activity.java

package com.mapsample.msclient009.scrollview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate ( savedInstanceState );
        setContentView ( R.layout.activity_main );
    }
}

                                  Android ScrollView Control


Leave Comment

Comments

Liked By