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
Related
I need a vertical ViewPager that has selected view always on center.
Something like Android's gallery widget works (selected element is always in center).
I have tried to implement vertical Gallery, but since it's deprecated...I would like to have this functionality via ViewPager.
Is there a way to manage that selected view is always on the center?
Also how to manage scroll amount of ViewPager?
For example...when I scroll trough the content I want to scroll for exactly one element's height.
Also I need mechanism how to define exact amouth of pixels for scrolling list view.
When list scroll I don't want it to only show next item, but to scroll for exact amount of pixels to always show the part of the following item.
Tnx for your help!
Im not sure if i understund the question. Isn't it as easy as this?
viewPager.setCurrentItem(viewager.getAdapter().getCount()/2)
About scrolling the pager to an specific amount of pixels,
You have to signal the ViewPager by calling beginFakeDrag() and endFakeDrag() on it. After starting a fake drag you can use fakeDragBy(float) to drag the ViewPager by the given amount of pixels
I was looking to create a GridView that stretches across the entire screen. However, when the user first opens the screen, the top of the first item should be about halfway up the screen.
For example lets say we have a GridView of 12 items displayed 3 x 4. When the user first opens the screen, only the first six items would be seen with a large margin at the top of the screen. The user can then scroll the list to see the other items. The top items would eventually reach all the way to the top of the screen.
If I was using a ListView, this is simple. I merely create a 0dp headerView with a large top margin. But, GridViews do not allow for headers. What is the best way to handle this situation?
Normally, you DO NOT make a GridView inside a ScrollView. It's not recommended! But sometimes you have no choice and you need to addHeaderView() on a GridView (But I repeat, it isnt recommended).
So, to make this happen, you have to make a custom GridView. This answer will be usefull in your case: Grid of images inside ScrollView
I had a same situation and I used this one: HFGridView by #SergeyBurish! Very simple and really great. (See the last answer here: A GridView with header and footer).
Hope this will be helpful.
I have multiple textviews inside a horizontalscrollview. Now I want to scroll all the textviews inside it so that all multiple textviews gets displayed. How can I achieve it ?
Thanks in advance.
Here is one git project. Its a scroller the scroll automatically and continously. It was made to show a credits screen by continously scrolling through a list of images.
This might help you or give you some idea.
https://github.com/blessenm/SlideshowDemo
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. :)
I have 3 ImageViews in LinearLayout(Horizontal Orientation). I want to show them according to move touches to the left or right. First of all, I have to create 3 imageviews inside of the LinearLayout and only the one of the 3 imageviews can be visible. In TouchEvent I want to change position of the visible one,then I want to show smoothly the other one like books in iBooks. How can I do that?
Best Regards,
You can refer below example. This will be helpful to you.
here