-1

I have a layout that is like this

RelativeLayout

ScrollView 
 RelativeLayout
       TextView
       ListView
       .....
       ExpandableTextView
       Button

        ....
        other Listviews
        ....
        Adview

....

ListViews element are loaded by AsyncTask. On button click expandableTextView expands or collapses.

Problem is that when i collapse expandableTextView,the view is not moving up. I've tried scrollTo method,but is not working...

     button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

              if(...) {

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            final ScrollView sv = (ScrollView) findViewById(R.id.sv);
                            sv.scrollTo(0,descTxt.getTop());;
                        }
                    });
                }
                else{                     
                }
            }
        });

I've tried implement above in onCreate and then in onPostExecute of asynctask but nothing happens. Whats going wrong? Thanks!!

Is it possible that is not working because of asynctask or because of that scrollview changes size dynamically according to elements?

Simos
  • 1
  • 1

1 Answers1

0

Use this code, I hope is work for you.

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        ScrollView sv = (ScrollView) findViewById(R.id.sv);
        sv.smoothScrollTo(0,0);
    }
}, 200);
Kishan Donga
  • 2,851
  • 2
  • 23
  • 35