Eddie Kamand
Eddie Kamand

Reputation: 247

Changing Button position to top when clicked

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

Answers (2)

JBirdVegas
JBirdVegas

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

Shreyash Mahajan
Shreyash Mahajan

Reputation: 23596

You can achive your goal as JBirdVegas said or you can do one quick thing is. . .

  1. Make ListView with Button on every index
  2. 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

Related Questions