Tuesday, March 16, 2021

Android VerticalScrollView

 

Android ScrollView (Vertical)

The android.widget.ScrollView class provides the functionality of scroll view. ScrollView is used to scroll the child elements of palette inside ScrollView. Android supports vertical scroll view as default scroll view. Vertical ScrollView scrolls elements vertically.

Android uses HorizontalScrollView for horizontal ScrollView.

Let's implement simple example of vertical ScrollView.


activity_main.xml

Now, drag ScrollView from palette to activity_main.xml file and place some palette element inside it.

File: activity_main.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:paddingBottom="@dimen/activity_vertical_margin"  
  7.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  8.     android:paddingRight="@dimen/activity_horizontal_margin"  
  9.     android:paddingTop="@dimen/activity_vertical_margin"  
  10.     tools:context="com.example.test.scrollviews.MainActivity">  
  11.   
  12.   
  13.     <TextView  
  14.         android:layout_width="wrap_content"  
  15.         android:layout_height="wrap_content"  
  16.         android:textAppearance="?android:attr/textAppearanceMedium"  
  17.         android:text="Vertical ScrollView example"  
  18.         android:id="@+id/textView"  
  19.         android:layout_gravity="center_horizontal"  
  20.         android:layout_centerHorizontal="true"  
  21.         android:layout_alignParentTop="true" />  
  22.   
  23.   
  24.     <ScrollView android:layout_marginTop="30dp"  
  25.         android:layout_width="fill_parent"  
  26.         android:layout_height="wrap_content"  
  27.         android:id="@+id/scrollView">  
  28.   
  29.   
  30.         <LinearLayout  
  31.             android:layout_width="fill_parent"  
  32.             android:layout_height="fill_parent"  
  33.             android:orientation="vertical" >  
  34.   
  35.             <Button  
  36.                 android:layout_width="fill_parent"  
  37.                 android:layout_height="wrap_content"  
  38.                 android:text="Button 1" />  
  39.             <Button  
  40.                 android:layout_width="fill_parent"  
  41.                 android:layout_height="wrap_content"  
  42.                 android:text="Button 2" />  
  43.             <Button  
  44.                 android:layout_width="fill_parent"  
  45.                 android:layout_height="wrap_content"  
  46.                 android:text="Button 3" />  
  47.             <Button  
  48.                 android:layout_width="fill_parent"  
  49.                 android:layout_height="wrap_content"  
  50.                 android:text="Button 4" />  
  51.             <Button  
  52.                 android:layout_width="fill_parent"  
  53.                 android:layout_height="wrap_content"  
  54.                 android:text="Button 5" />  
  55.             <Button  
  56.                 android:layout_width="fill_parent"  
  57.                 android:layout_height="wrap_content"  
  58.                 android:text="Button 6" />  
  59.             <Button  
  60.                 android:layout_width="fill_parent"  
  61.                 android:layout_height="wrap_content"  
  62.                 android:text="Button 7" />  
  63.             <Button  
  64.                 android:layout_width="fill_parent"  
  65.                 android:layout_height="wrap_content"  
  66.                 android:text="Button 8" />  
  67.             <Button  
  68.                 android:layout_width="fill_parent"  
  69.                 android:layout_height="wrap_content"  
  70.                 android:text="Button 9" />  
  71.             <Button  
  72.                 android:layout_width="fill_parent"  
  73.                 android:layout_height="wrap_content"  
  74.                 android:text="Button 10" />  
  75.             <Button  
  76.                 android:layout_width="fill_parent"  
  77.                 android:layout_height="wrap_content"  
  78.                 android:text="Button 11" />  
  79.             <Button  
  80.                 android:layout_width="fill_parent"  
  81.                 android:layout_height="wrap_content"  
  82.                 android:text="Button 12" />  
  83.             <Button  
  84.                 android:layout_width="fill_parent"  
  85.                 android:layout_height="wrap_content"  
  86.                 android:text="Button 13" />  
  87.             <Button  
  88.                 android:layout_width="fill_parent"  
  89.                 android:layout_height="wrap_content"  
  90.                 android:text="Button 14" />  
  91.             <Button  
  92.                 android:layout_width="fill_parent"  
  93.                 android:layout_height="wrap_content"  
  94.                 android:text="Button 15" />  
  95.             <Button  
  96.                 android:layout_width="fill_parent"  
  97.                 android:layout_height="wrap_content"  
  98.                 android:text="Button 16" />  
  99.             <Button  
  100.                 android:layout_width="fill_parent"  
  101.                 android:layout_height="wrap_content"  
  102.                 android:text="Button 17" />  
  103.             <Button  
  104.                 android:layout_width="fill_parent"  
  105.                 android:layout_height="wrap_content"  
  106.                 android:text="Button 18" />  
  107.   
  108.             <Button  
  109.                 android:layout_width="fill_parent"  
  110.                 android:layout_height="wrap_content"  
  111.                 android:text="Button 19" />  
  112.             <Button  
  113.                 android:layout_width="fill_parent"  
  114.                 android:layout_height="wrap_content"  
  115.                 android:text="Button 20" />  
  116.   
  117.         </LinearLayout>  
  118.   
  119.     </ScrollView>  
  120.   
  121. </RelativeLayout>  

Activity class

In activity class, we have not changed any code.

File: MainActivity.java

  1. package com.example.test.scrollviews;  
  2.   
  3. import android.support.v7.app.AppCompatActivity;  
  4. import android.os.Bundle;  
  5.   
  6. public class MainActivity extends AppCompatActivity {  
  7.   
  8.     @Override  
  9.     protected void onCreate(Bundle savedInstanceState) {  
  10.         super.onCreate(savedInstanceState);  
  11.         setContentView(R.layout.activity_main);  
  12.     }  
  13. }  

Output

android ScrollView Vertical 1
android ScrollView Vertical 2

No comments:

Post a Comment

Inapp update

  Inapp update https://desk.zoho.com/portal/vegabirdtech/en/kb/articles/how-to-use-burp-suite-with-android-mobile