1

EDIT: solved! Awnser 1. can't push/vote it up

I'm trying to figure out for hours what's the best way to make an "closing credits" activity. Right now I have a TableLayout inside a RelativeLayout to center the table. I am using a simple animation file:

<translate
android:duration="20000" 
android:fromYDelta="100%p"
android:toYDelta="-100%p" /> 

The problem is, the credits table is much bigger than the screen, around 4 times bigger so the table gets cut at screen dimension. Animation works fine, but only the viewable part of the table walks through the display.

Is there a smarter way to create closing credits? Is it possible in android to not cut the table at display dimensions?

Maybe this is too much text anyway? (with ScrollView I get "View too large to fit into drawing cache")

EDIT: With Luksprog help I got the whole table to scrolldown. Like already mentioned, it's much to fast now. Now I have problems to control the speed via an handler or timertask. because to display and make the table scrollable, i found in the web this solution, otherwise it didn't scroll:

public class Credits extends Activity {
int mesuredHeightScroll;
ScrollView scroll;
boolean first_time = true;

protected void onCreate(Bundle savedInstanceState) {
    if (first_time == true) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.credits);
        scrolldownthetable();
    }
}

private void scrolldownthetable() {
    // TODO Auto-generated method stub
    final ScrollView scroll = (ScrollView) findViewById(R.id.scrolltable);
    TableLayout table = (TableLayout) findViewById(R.id.table);

    OnGlobalLayoutListener listener = new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            scroll.smoothScrollTo(0, mesuredHeightTable);

        }
    };
    table.getViewTreeObserver().addOnGlobalLayoutListener(listener);
};

/**
 * Draw the Layout, otherwise getMesuredHeight returns 0, null onCreate 
 * to call it again, first time to false, so onCreate doesn't call again on
 * focus change (resume,pause...)
 */
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    ScrollView scroll = (ScrollView) findViewById(R.id.scrolltable);
    TableLayout table = (TableLayout) findViewById(R.id.table);
    mesuredHeightTable = table.getMeasuredHeight();
    mesuredHeightScroll = scroll.getMeasuredHeight();

    onCreate(null);
    first_time = false;
}

}

Is there anyway to get this scrollTo() automated inside the Globallayoutlistener? Or is my code stupid and theres a more comfortable way? It would be great if someone could help me with some code, because i am running out of time :/

eyjin
  • 15
  • 3

1 Answers1

0

Is there a smarter way to create closing credits? Is it possible android not to cut the table at displydimensions?

As your table is most likely enclosed in a ScrollView you could add another view at the bottom that is as big as the screen and then use the smoothScrollTo() on the ScrollView itself.

As you probably want more control over the animation, especially the speed, I think you could use a Handler or CountDownTimer to simply call scrollTo() on the ScrollView at short time intervals.

user
  • 86,916
  • 18
  • 197
  • 190
  • when i set scroll.smoothScrollTo(int,int); what should be the x and y ints like? when i add a view at the bottom as big as the screen, would that be enough, cause my table is like 4 times larger than screensize. thx – eyjin Jun 23 '13 at 13:17
  • @eyjin `x` would be 0 and `y` would be the sum of all the views heights(`view.getMeasuredHeight()`) from the `ScrollView` without the last added empty view. – user Jun 23 '13 at 14:00
  • hey Luksprog, maybe you could help me with the new code i posted? Thank you so far – eyjin Jun 24 '13 at 09:12
  • @eyjin I've made a little sample about this. You can find it here https://github.com/luksprog/DroidPlayground/blob/master/src/com/luksprog/playground/view/RollingCredits.java . It's self explanatory but ask if you have problems. – user Jun 24 '13 at 12:16
  • wow thanks a lot, you blew me away :D it works fine! I hope others will benefit too from your work! – eyjin Jun 24 '13 at 19:27
  • @eyjin No problem. If my answer helped you could mark it as correct with the check mark near the answer. – user Jun 24 '13 at 19:46