Wednesday 18 October 2017

13. Using Scrollview in Android

13. Using Scrollview in Android


A view group that allows the view hierarchy placed within it to be scrolled. Scroll view may have only one direct child placed within it. To add multiple views within the scroll view, make the direct child you add a view group, for example LinearLayout, and place additional views within that LinearLayout.
Scroll view supports vertical scrolling only. For horizontal scrolling, use HorizontalScrollView instead.
Never add a RecyclerView or ListView to a scroll view. Doing so results in poor user interface performance and a poor user experience.

Some points for Scroll View:


  1. ScrollView can hold only one direct child. This means that, if you have complex layout with more view controls, you must enclose them inside another standard layout like LinearLayout, TableLayout or RelativeLayout.
  2. You can specify layout_height and layout_width to adjust height and width of screen.
  3. Scrollview is ideal for screens where scrolling is required, but it is an overhead when scroll view is used to render a larger list of data. Android provides specialized adapter views like ListView, GridView and Recycler View (Introduced in Android Lollipop) are recommended for long lists.
  4. You should never use a ScrollView with a ListView or GridView, because they both takes care of their own vertical scrolling.
  5. ScrollView only supports vertical scrolling. Use HorizontalScrollView for horizontal scrolling.
  6. The android:fillViewport property defines whether the scrollview should stretch its content to fill the viewport. You can set the same property by calling setFillViewport(boolean) method.

ScrollViewActivity.java

package tutorial.android.sachin4droid.androidtutorials;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class ScrollViewActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_scroll_view);
  }
}

Activity_scroll_view.xml


<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView android:layout_height="match_parent" android:layout_width="match_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout 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="tutorial.android.sachin4droid.androidtutorials.ScrollViewActivity">
  <TextView
      android:id="@+id/scrollViewTestTextView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:textSize="30dp"
      android:text="ScrollView can hold only one direct child. This means that, if you have complex layout with more view controls, you must enclose them inside another standard layout like LinearLayout, TableLayout or RelativeLayout.
You can specify layout_height and layout_width to adjust height and width of screen.
Scrollview is ideal for screens where scrolling is required, but it is an overhead when scroll view is used to render a larger list of data. Android provides specialized adapter views like ListView, GridView and Recycler View (Introduced in Android Lollipop) are recommended for long lists.
You should never use a ScrollView with a ListView or GridView, because they both takes care of their own vertical scrolling.
ScrollView only supports vertical scrolling. Use HorizontalScrollView for horizontal scrolling.
The android:fillViewport property defines whether the scrollview should stretch its content to fill the viewport. You can set the same property by calling setFillViewport(boolean) method."
      />
</LinearLayout>
</HorizontalScrollView>





No comments:

Post a Comment

Extract error records while inserting into db table using JDBCIO apache beam in java

 I was inserting data into postgres db using apache beam pipeline. it works perfectly with JdbcIO write of apache beam library. But, now, i ...