
Untitled
By: a guest on
May 6th, 2012 | syntax:
None | size: 2.16 KB | hits: 24 | expires: Never
ScrollView sliding from bottom to top, programmatically
sv = (ScrollView)findViewById(R.id.scroll_text);
@Override
public void onStart()
{
super.onStart();
sv.post(new Runnable() {
@Override
public void run() {
sv.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
if (hasFocus)
{
int display_h = display.getHeight();
pos_y = display_h;
mScrollHandler.removeCallbacks(mUpdateScroll);
mScrollHandler.postDelayed(mUpdateScroll, 0);
}
else
{
mScrollHandler.removeCallbacks(mUpdateScroll);
}
}
private Runnable mUpdateScroll = new Runnable() {
public void run() {
pos_y = pos_y - 1;
sv.scrollTo(0, pos_y);
mScrollHandler.postDelayed(mUpdateScroll, 100);
}
};
display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int display_h = display.getHeight();
pos_y = display_h;
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
if (hasFocus)
{
RelativeLayout r_main = (RelativeLayout)findViewById(R.id.RelativeTables);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)r_main.getLayoutParams();
params.leftMargin = 0;
params.topMargin = pos_y;
r_main.setLayoutParams(params);
mScrollHandler.removeCallbacks(mUpdateScroll);
mScrollHandler.postDelayed(mUpdateScroll, 0);
}
else
{
mScrollHandler.removeCallbacks(mUpdateScroll);
}
private Runnable mUpdateScroll = new Runnable() {
public void run() {
pos_y = pos_y - 1;
RelativeLayout r_main = (RelativeLayout)findViewById(R.id.RelativeTables);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)r_main.getLayoutParams();
params.leftMargin = 0;
params.topMargin = pos_y;
r_main.setLayoutParams(params);
mScrollHandler.postDelayed(mUpdateScroll, 100);
// the running cycle:
if (pos_y<-display.getHeight()) {
pos_y = display.getHeight();
}
}
};