Scrolling a view from another view
<p>I have a Horizontal Scroll view in my layout. It contains a a linear layout(orientation vertical) which in turn contains buttons. in this area I can horizontally scroll (The buttons don't fit together in one screen at a time in most phones). Android provides me this comfort. Now below this horizontal scroll view, there is a Relative layout. <br>Now what I want is, when I swipe horizontally in the Relative Layout, I want the buttons in the horizontal scroll view to scroll.<br>
I have tried to implement this by overriding the <code>onTouchEvent()</code>. The problem with this is that, the buttons scroll infinitely(they go out of the screen). I am not able to put a limit. I tried to put a limit. But some how it exceeds the limit by 1 and stops. Then I am not able to scroll.<bR>
<strong>This is my layout :</strong><br></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:focusableInTouchMode="true" &gt;

    &lt;HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;
    &lt;LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"  
        android:id="@+id/llt"
        &gt;

        &lt;Button
        android:id="@+id/login"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:background="@drawable/button1"
        style="@style/ButtonText"
       android:text="Groups" /&gt;

        &lt;Button 
            android:id="@+id/login1"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:background="@drawable/button1"
        style="@style/ButtonText"
            android:text="QandA"/&gt;
                &lt;Button 
            android:id="@+id/login2"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:background="@drawable/button1"
            style="@style/ButtonText" 
            android:text="Pending Requests"/&gt;
            &lt;Button
            android:id="@+id/login3"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:background="@drawable/button1"
            style="@style/ButtonText"
            android:text="Settings"
            &gt;&lt;/Button&gt;
                        &lt;Button 
            android:id="@+id/login4"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:background="@drawable/button1"
        style="@style/ButtonText" 
            android:text="Help"/&gt;
    &lt;/LinearLayout&gt;        
        &lt;/HorizontalScrollView&gt;

    &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/rl1"
     android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
   &gt;
    .
    .
    .
</code></pre>

<p><br>
<strong>This is what I have tried :</strong><br></p>

<pre><code>@Override 
 public boolean onTouchEvent(MotionEvent event) {
   switch (event.getAction()) {
       case MotionEvent.ACTION_DOWN: {
           currentX = (int) event.getRawX();
           currentY = (int) event.getRawY();
           break;
       }

       case MotionEvent.ACTION_MOVE: {
           int x2 = (int) event.getRawX();
           int y2 = (int) event.getRawY();
           if(location1[0]&lt;=leftconst&amp;&amp;(location2[0]+rightmost.getWidth())&gt;=rightconst)
           {
           llt.scrollBy(currentX - x2 ,0);
           }
           currentX = x2;
           currentY = y2;
           break;
       }   
       case MotionEvent.ACTION_UP: {
           break;
       }
   }
     return true; 
 }
</code></pre>

<p><br>
<code>leftconst</code> and <code>rightconst</code> are equal to 3 and <code>screenwidth</code>, respectively. But when scrolling it it stops a both ends. Then after that scrolling is not possible. <code>leftmost</code> is the button with id <code>login</code> and <code>rightmost</code> is the button with id <code>login4</code></p>
