You are here

Chapter 40: Fill in the blanks #1 - The Credits page

Now we can't wait any longer. We need to do something about the "How-to" and "Credits" pages.

I know it's a bit boring since they aren't part of the actual game, but it's still good practice ;-)

We did the very basics in chapter 10, but we only printed the word "Credits" in a TextView at that time. I want to provide a bit more info than that ;-)

I was still thinking about a static page though, with a few lines mentioning that JustRoids is part of a tutorial (with a link to this site) and a special thanks to Martin Felis for the asteroid image used in the game: 

We did a simple xml-file (res/layout/credits.xml) in chapter 10, but it's not really suitable to use that to build the whole page as I now want it. We can keep the file however, but we will have to rewrite it so that we have two different TextViews in it; one for the heading and one for the body text. We also have to add id:s to the TextViews, so that we can access them from our Java code and handle the rest there. So open up credits.xml and change it to:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/creditsHeadingView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dip"
        android:gravity="center_horizontal"
        android:text="@string/credits"
        android:textSize="40dip" />

    <TextView
        android:id="@+id/creditsBodyView"
        android:layout_marginLeft="30dip"
        android:layout_marginRight="30dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/credits" />

</LinearLayout>

 Then we will have to switch over to CreditsActivity.java and handle the actual printout there:

package com.ajomannen.justroids;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

public class CreditsActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.credits);

        // New block to print the body text in the Credits page
        TextView textView = (TextView) findViewById(R.id.creditsBodyView);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        String text = "JustRoids is a game written by Anders Ekstrand as a part of an Android Game "
                + "Development Tutorial published at <a href=\"http://www.benareby.com/tutorial/\">"
                + "www.benareby.com/tutorial</a>, where all source code is available.<br/><br/>"
                + "A very special thank to Martin Felis, who made the asteroid image that plays a central "
                + "part in this game.";
        textView.setText(Html.fromHtml(text));
        // End of body text block
    }
    
}

That's it:

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer