Reputation: 247
I have a linear layout with about 20 buttons. I want to be able to change the button's position to the top of the screen when clicked. for example. the user clicks button # 7 i want the layout to scroll automatically so button #7 is on the top position of the screen. please help out with some code
Thanks for Viewing
Upvotes: 0
Views: 177
Reputation: 11413
Place your LinearLayout
in a ScrollView
Grab a reference to your ScrollView
then in the onClick
of the buttons use
http://developer.android.com/reference/android/widget/ScrollView.html#smoothScrollTo(int, int)
to scroll to the desired location.
Upvotes: 1
Reputation: 23596
You can achive your goal as JBirdVegas said or you can do one quick thing is. . .
Now onItemClickListener of the listview put below code and pass pressed index.
setSelection(index)
e.g.
you can use `setSelection(index)` so the display will jump to the index you want
Hope you will get the point.
Enjoy Coding. :)
Upvotes: 0