Android Automatic Horizontal Scroll View

Android Automatically Scrolling UI Component
·        Horizontal ScrollView :
1.       Add this layout Component to <layout>.xml of screen to which you want to add Horizontal Automatic Scroll

<HorizontalScrollView android:layout_width="match_parent"

      android:layout_height="wrap_content"
android:id="@+id/horiztonal_scrollview_id" android:fadingEdge="none">

<LinearLayout android:id="@+id/horiztonal_outer_layout_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:background="#ffffff" android:gravity="center_vertical"
                  android:paddingTop="5dip" android:paddingBottom="5dip">
            </LinearLayout>
</HorizontalScrollView>

2.       HorizontalScrollingLayout.java

1.       This view is responsible for automatically scrolling the view.
2.       It is same as Horizontal Scroll View but automatic scrolling is enabled.
3.       Automatic Scrolling is enabled by scrolling programmatically at regular time interval which can be given in milliseconds.
4.       As this view is ListAdapter category, it needs to extend AdapterView<ListAdapter> class.
5.       To enable touch gesture and mouse/pen movement on this Horizontal Scroll view, GestureDetector and MotionEvent respectively.
6.       onSingleTapConfirmed function helps if we Tap or select a element in list.
7.       onLayout(. . . .) function decides scrolling parametrs like -
Scroll Start Position,Scroll Offset and controls scrolling when start and end points are reached.
8.       mScroller.startScroll(mNextX, 0, x - mNextX, 0); actually starts scrolling with regular interval of 250 milliseconds.
9.       Gesture Listener enables catching users fling movment (Swipe Like movement). 



3.       HomeActivity.java
¨       Activity to which’s screen HorizontalScrollView to be added.
¨       As we have already added in step 1 – xml component in Layout.xml file of this screen.
¨       Now get that component in Activity Class.


horizontalScrollview  =
            (HorizontalScrollView)findViewById(R.id.horiztonal_scrollvew_id);
horizontalOuterLayout =                   (LinearLayout)findViewById(R.id.horiztonal_outer_layout_id);
horizontalTextView    = (TextView)findViewById(R.id.horizontal_textview_id);
       
        horizontalScrollview.setHorizontalScrollBarEnabled(false);


Example  : Download Complete Files from following Location.

1.HomeActivity java class :
https://www.dropbox.com/s/bn8oy9ojmxnwhbq/HomeActivity.java
2.HorizontialListView java class :
https://www.dropbox.com/s/qrse7gx32uihx8e/HorizontialListView.java

Comments

Popular posts from this blog

AWS S3 -- s3cmd tool setup on Windows

JAVA Recieve AWS SNS HTTP Notification using Servlet