I have been trying to set the initial position of a scroll View but have not found a way. Does anyone have any ideas? Also I have a GoogleMaps fragment as a children of the scroll View.
Thanks,
Ryan
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
In android, You can scroll the elements or views in both vertical and horizontal directions.
In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.
scrollEventThrottle: It is used to control the firing of scroll events while scrolling.
Yes, that is possible:
ScrollView.scrollTo(int x, int y);
ScrollView.smoothScrollTo(int x, int y);
ScrollView.smoothScrollBy(int x, int y);
can be used for that. The x and y parameters are the coordinates to scroll to on the horizontal and vertical axis.
Example in code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
sv.scrollTo(0, 100);
}
In that example, once the Activity
is started, your ScrollView
will be scrolled down 100 pixels.
You can also try to delay the scrolling process:
final ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
sv.scrollTo(0, 100);
}
}, 250); // 250 ms delay
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With