android


Trying to scroll up a scrollview in all apis


I'm using the next source code to scroll up a scrollview, but I've saw that the method removeOnGlobalLayoutListener isn't compatible under API 16.
public void scrollUp(){
// Wait until my scrollView is ready
sv_container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
// Ready, move up
sv_container.fullScroll(View.FOCUS_UP);
sv_container.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
Did you know a way to achieve this purpose in all APIs? Thanks
There's a deprecated method that does the same thing -
http://developer.android.com/reference/android/view/ViewTreeObserver.html#removeGlobalOnLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener).
Just make sure to use the new one where available.
SOLVED:
public void scrollUp(){
// Wait until my scrollView is ready
sv_container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
// Ready, move up
sv_container.fullScroll(View.FOCUS_UP);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
sv_container.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
sv_container.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}

Related Links

Android Studio: Import module window is too big, can't get any further?
How to clear focus of EditText under Fragment onResume() after manual input something in EditText
Show CollapsingToolbarLayout Title ONLY when collapsed doesn't work properly
Android studio doesn't recognize USB devices in ubuntu
How to get data in AutoCompleteTextView using mySQL and Json?
How to use colored strings in a listview?
Call Fragment method from activity using FragmentPagerAdapter
SSL connection reusing and caching with Android OkHttpClient
Android programming: ListActivity “suppresses” ActionBar
How to add a custom list view to AlertDialog in android?
Bottom Sheet below LinearLayout in Android
In sqlite database I insert the image and retrieve from it . But my image is not displaying in the list
Create custom Progressbar with color change at rotate in Android
Get media current position before disconnecting from cast
Which version of android gradle plugin i can use with gradle 2.14?
How To Remove my own app notification when I'm on the app

Categories

HOME
httparty
twitter-bootstrap-3
checkstyle
gpu
yahoo-finance
alarm
seo
tivoli
crystal-lang
opengl-3
modal-dialog
endeca
mod-security
radgridview
code-generation
modbus-tcp
android-7.0-nougat
digital-signature
lilypond
microsoft-ocr
strongname
fractions
user-defined-functions
iis-express
corenlp-server
scrollview
livelink
anki
kudu
powershell-ise
jbutton
fstream
mailkit
code-snippets
android-maps-extensions
dynamic-jasper
jwplayer6
hivemq
reason
setup.py
kill
levenshtein-distance
dbnull
sharp-snmp
ssrs-2014
oracle-service-bus
oim
optimizely
ntvs
user-defined-fields
dtsearch
zenhub
context-switch
java-6
oracleclient
check-mk
mouseleave
restore
node-request
pure-css
pytables
vulcanize
beamer
synonym
vorpal.js
eigenvector
pre-build-event
android-wake-lock
hadoop-partitioning
ikiwiki
uiactionsheet
design-principles
forwarding
google-books
jquery-forms-plugin
fits
code-documentation
variadic-templates
beatsmusic
unix-socket
malformedurlexception
dsym
twitter-bootstrap-rails
sphinxql
scrypt
c++builder-xe5
mysql-error-2013
monotouch.dialog
saleslogix
adobe-media-server
extconf.rb
koken
floating-point-exceptions
urlrewriter
silent
pos-for-.net
build-environment
purepdf
escrow
fail-fast-fail-early

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App