I have a view and a textview in a linearlayout. That LinearLayout is present in a ScrollView. I want that scrollView to move down onclicking a button in that screen and again move up onclicking that again
Asked
Active
Viewed 4,534 times
0
-
check this http://stackoverflow.com/questions/3080402/android-scrollview-force-to-bottom – kalyan pvs Mar 05 '15 at 04:59
-
how to slow it so that we can view that? – Srujana Dakoju Mar 05 '15 at 05:54
-
I am unable to figure out whether its scrolling or not – Srujana Dakoju Mar 05 '15 at 05:54
-
what about using scrollTo(x, y) method . With each click you can move view to some specific pixels. – Amarjit Mar 05 '15 at 06:37
-
i mentioned it as scrollTo(0,0). Then it has to go up but its not – Srujana Dakoju Mar 05 '15 at 06:58
2 Answers
1
To scroll down on button click you should use this:
scrollView.post(new Runnable()
{
@Override
public void run()
{
//X,Y are scroll positions untill where you want scroll down
scrollView.scrollTo(X, Y);
}
});
To scroll up on button click you should use this:
scrollView.post(new Runnable()
{
@Override
public void run()
{
//X,Y are scroll positions untill where you want scroll up
int X=0,Y=0;
scrollView.scrollTo(X, Y);
}
});

Amrut Bidri
- 6,276
- 6
- 38
- 80
-
Its not working. I have a ImageButton at the parentbottom and ScrollView in a LinearLayout below that. I want to move the layout in scrollview up on click of Image Button – Srujana Dakoju Mar 06 '15 at 06:13
1
Try this -
private ImageView list_scroll_iv;
private int focus_pos=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_scroll_iv = (ImageView)findViewById(R.id.list_scroll_iv);
list_scroll_iv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
list_sv.post(new Runnable() {
@Override
public void run() {
//1 for up and 2 for down
if(focus_pos==1) {
list_sv.fullScroll(ScrollView.FOCUS_DOWN);
focus_pos=2;
list_scroll_iv.setImageDrawable(getResources().getDrawable(R.drawable.blue_arrow_ic_up));
}
else {
list_sv.fullScroll(ScrollView.FOCUS_UP);
focus_pos=1;
list_scroll_iv.setImageDrawable(getResources().getDrawable(R.drawable.blue_arrow_ic_down));
}
}
});
}

Chirag Jain
- 628
- 11
- 24