Add left to right screen scrolling feature in android on TextView to scroll text.
Horizontal scrollview is same as vertical scroll view but there is a major difference between both of them. Horizontal scroll view scrolls left to right on android screen and developer can add multiple widgets like button, textview, edittext and the automatically scrolls left to right on activity. So here is the complete step by step tutorial for Android Horizontal ScrollView example tutorial .
Android Horizontal ScrollView example tutorial .
Code for MainActivity.java file.
package com.android_examples.com.scrollviewhorizontal; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Code for activity_main.xml layout file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="horizontal" tools:context="com.android_examples.com.scrollviewhorizontal.MainActivity" > <HorizontalScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextBox 1" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_gravity="center" android:layout_marginTop="20dp" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextBox 2" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_gravity="center" android:layout_marginTop="20dp" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" android:layout_gravity="center" android:layout_marginTop="20dp" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" android:layout_gravity="center" android:layout_marginTop="20dp" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 3" android:layout_gravity="center" android:layout_marginTop="20dp" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 4" android:layout_gravity="center" android:layout_marginTop="20dp" /> </LinearLayout> </HorizontalScrollView> </LinearLayout>
Screenshot: