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
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.
You can achive your goal as JBirdVegas said or you can do one quick thing is. . .
Make ListView with Button on every index
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. :)
Related
I want to create something like a Scrollview in the Activity with Listview from list_0 to list_20.
Now when i touch and Scroll down i want to display a small tag near the scrollview indicating the row number and it should disappear after sometime.
Please help me i need this to be done in few hour
thanks in advance
Get the that list item position and display that one in textview.
for eg., take two textview in horizontal mode this xml file add to the listview using layout inflater. first time the second textview take invisible state and when you click scrollview get the near list item position.create scrollview one id.
I have a scrollview inside which I have 5 imageviews say IMV1,IMV2...IMV5 . Now on scrolling,one by one all imageviews are shown in device screen. Now I have a drawer with 5 buttons say 1,2 ..5.
Now take us a scenario,
Currently I am on first imageview. Now when I click on button 5 in the drawer.
I need IMV5 to show on the screen without scrolling.It can be obtained
through smoothScrollBy/scrollTo to y equal to 5*screenHeight. But here it
scrolls through all intermediate imageviews.
Please note,I don't wish to affect scroll feature.For above example,
After I reach IMV5,when I scroll up,it should scroll to IMV4 and so on.
Is there any way to obtain it .Please suggest.
Thanks In Advance.
P.S. If you need some more clarification,please let me know.
You can achieve this easily using a ListView instead of ScrollView.
What you can do is:-
Add all the imageviews to a ListView.
This will fulfill your scrolling requirement, as ListView automatically handles scrolling if its content's size is grater than the screen size.
Now use the listView.setSelection(position) on click of the buttons.
It will scroll to the selected imageview without giving the scrolling effect
Hope this helps.
It can be achieved through ScrollView too.. All you need to do is get the View at that position. Then call requestFocus() on the obtained view.
For example:- If you press Button 5, then IMV5.requestFocus() will do it for you
Is it possible to have an activity scroll down to a certain point when a button is clicked?
I want my activity to behave just like an anchor in a web page.
I have two buttons at the top of the activity, followed by lengthy text aboout each of the buttons. When I click on the button at the top I want the page to scroll down beginning of that button's description.
Is this possible?
Assuming you are using a TextView to display your text, you use the built in scrolling function myTextView.scrollTo(x,y). Put it inside your buttons' onClicks and you should be good to go!
http://developer.android.com/reference/android/widget/TextView.html
So your outer layout is a scroll view?
You can call
View.requestFocus()
Obviously, the view has to be focusable.
The problem with scrollTo(x,y) mentioned above is most likely that you don't know x, y.
I added a ListView and a Button to a layout.
What I want to do is, when I click the button, the ListView should scroll to a specified item such as the 10th to the top. But I don't want it to scroll too fast like flipping a page.
How can I do this? Can I add a fraction to a ListView? If so, how can this be archived?
i haven't try it but you can use "setSmoothScrollingEnabled(boolean smoothScrollingEnabled)" method of listview.
i think this will help you.
I jave a list of item (linearlayout inside a scrollview where i add buttons vertically to linearlayout dynamically from the java code ) ? i need when i click on one button the item moves up (scroll up) , to make the item at the first of the screen ??!
Well I never did that, but from the ListView reference it seems pretty clear that set setSelectionFromTop is what you are searching for.
See also how-to-autoscroll-a-list-view-in-android