1

In my Android app, I have a few views (Buttons, EditTexts etc.) not visible initially. These are visible only on a particular button click event. I wish to move the scrollview to the end of these views so that these are visible to the user.

The relevant portion of the layout file:

    <ScrollView...>

    <RelativeLayout android:id="@+id/RelDevDet"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            .
            .
            .
            <ImageButton android:id="@+id/ibRateApp"
                android:layout_toRightOf="@id/tvRateApp"
                android:layout_alignTop="@id/tvRateApp"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:background="@drawable/arrow_up" android:clickable="true"
                android:layout_marginRight="5dp"
                android:paddingBottom="10dp"
                 />
            <RatingBar android:id="@+id/rtApp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/tvRateApp"
                android:layout_marginLeft="5dp" android:visibility="gone"/>
            <EditText android:layout_width="fill_parent"
                android:id="@+id/etRateApp"
                android:layout_height="wrap_content" 
                android:lines="3"
                android:layout_below="@+id/rtApp"
                android:layout_marginRight="5dp"
                android:layout_alignLeft="@+id/tvDevWeb"
                android:visibility="gone" />
            <Button android:id="@+id/btSubRat" android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:layout_below="@+id/etRateApp" android:layout_margin="5dp" android:text="Submit" android:visibility="gone"/>
        </RelativeLayout>
        </ScrollView>

The onclicklistener for the button is:

public void onClick(View v) {
if(v.getId()== R.id.ibRateApp){
            Log.d("amit","scroll end");
            rtApp.setVisibility(View.VISIBLE);
            etRateApp.setVisibility(View.VISIBLE);
            //How to get the scrollview move to the end of the page here??
        }
}
ambit
  • 1,099
  • 2
  • 28
  • 43

5 Answers5

8
scroll.fullScroll(View.FOCUS_DOWN);

This fixed it for me.

ambit
  • 1,099
  • 2
  • 28
  • 43
3

If the layout has a hidden view it's safe to use post delay so that the method will only be called after making the view visible so that it work scroll down to the end of the page by considering the hidden view

int SPLASH_TIME_OUT = 10;

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                invisibleview.setVisibility(View.VISIBLE);
                scrollView.fullScroll(View.FOCUS_DOWN);
                if (invisibleview.getVisibility() == View.VISIBLE){

                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            // This method will be executed once the timer is over
                            scrollView.fullScroll(ScrollView.FOCUS_DOWN);
                        }
                    }, SPLASH_TIME_OUT);
                    scrollView.fullScroll(View.FOCUS_DOWN);
                }
            }
        });
Dhyan V
  • 621
  • 1
  • 8
  • 18
0

use

 mScrollViewLayout.scrollTo(0, mScrollViewLayout.getMaxScrollAmount ());
asloob
  • 1,308
  • 20
  • 34
  • Thanks. Do I need to do anything else here. Adding this line gives me a null pointer exception, although I have used defined and used ScrollViewLayout in other parts of code as well. Anything to do for getMaxScrollamount()? – ambit Dec 04 '12 at 08:41
  • No, this should be sufficient. Try to find why you are getting the null pointer exception on mScrollViewLayout if you have initialised it properly – asloob Dec 04 '12 at 11:28
  • The null pointer exception is not an issue. The problem was that the variable was duplicated in an inner block of code and was not initialized. But still, getMaxScrollAmount() method does not lead me to the end of the scrollview. Perhaps it is somewhat related to this problem http://stackoverflow.com/questions/7635903/get-maximum-horizontalscrollview-scroll-amount/7636459 I ll try to fix this and post a solution. In case you come up with something, do let me know. Thanks – ambit Dec 05 '12 at 10:06
  • Does the scrollview scroll a little or none at all? – asloob Dec 05 '12 at 10:45
  • It scrolls but only around to the middle of the page and not the end. – ambit Dec 05 '12 at 10:53
0
 await Task.Delay(500);
 scrollView1.FullScroll(FocusSearchDirection.Down);

FOR XAMARIAN ANDROID IT WORKS FOR ME

-2

//Hey sir, i would urge you instead of writing to much code , just call the ScrollView with findviewByid on the onclickLIstener method add.

    scrollview.fullScroll(View.FOCUS_UP); Or
    scrollview.fullScroll(View.FOCUS_DOWN); 
Mandy
  • 17
  • 4