« タイトルバーとアイコン その2 | メイン | namie amuro LIVEGENIC 2015-2016 »

Android

簡易エンドロール

endrollMin SDK Version 10
Android 2.3.4端末 HTC EVO ISW11HT
Android 4.2.2端末 Samsung GALAXY NEXUS SC-04D
Android Studio 1.5.1

ジョークアプリを作った際に試した簡単なエンドロール。
Empty Activity でプロジェクトを新規作成▼

 ↓
endroll
●スクロールさせたいテキストなど。
app/src/main/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"⁄>
<resources>
	<string name="app_name">エンドロール</string>
	<string name="endrool">HOPE TO BE PEACEFUL WORLD.
\n
\nAND THANK THE WORLD FOR LOVE.
\n
\n<b><FONT COLOR="#ff8c00">REMIX.ASIA</FONT></b>
\n
\n
\n
\n[Making Staff]
\n
\nDancer Cooedinator wanko
\n
\nTotal Designer wanko
\n
\n
\nSound Designer wanko
\n
\nMonitor Enginer wanko
\n
\n
\nSwitcher wanko
\n
\n
\nHair and Make Up wanko
\n
\n
\nStylist wanko\'s owner
\n
\n
\nOfficial fan Club REMIX.ASIA
\n
\n
\n
\n
\n
\n
\n
\n
\n
\nTHE END
	</string>
</resources>
英語版 app/src/main/res/value/strings.xml も同様に。
●シンプルなレイアウト。
app/src/main/res/layout/endroll.xml
<?xml version="1.0" encoding="utf-8"⁄>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black"
    tools:context=".ActivityEndroll">
    <TextView
        android:id="@+id/textView"
        android:text="@string/endrool"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:autoText="false"
        android:gravity="center"
        android:textColor="@android:color/white"
        android:textSize="10dp" />
</LinearLayout>
●オブジェクトが下から上へゆっくりスクロールするアニメーション定義。
app/src/main/res/anim/endrool.xml
<?xml version="1.0" encoding="utf-8"⁄>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="true"
    android:fillEnabled="true"
    android:fillBefore="true"
    android:fillAfter="true"
>
    <translate
        android:fromYDelta="100%p"
        android:toYDelta="-80%p"
        android:duration="30000"
    />
</set>
●こちらのスタイルで背景色も暗く。
app/src/main/res/values/styles.xml
<resources>

    <!-- Base application theme. -->
    <!-- style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> ←★変更
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>
●縦長画面に固定したほうが無難。
app/src/main/AndroidManifest.xml
<activity
        :
    android:screenOrientation="portrait" ←★追加
        :
●必要最小限のActivity。アニメーション終了イベントでエンドロールアプリ THE END。
app/src/main/java/asia/remix/endroll/ActivityEndroll.java
package asia.remix.endroll;

import android.os.Bundle;
import android.app.Activity;

import android.widget.TextView;

import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;

public class ActivityEndroll extends Activity{
    private TextView textView;
    private Animation animationEndrool;

    @Override
    protected void onCreate( Bundle savedInstanceState ){
        super.onCreate( savedInstanceState );
        setContentView( R.layout.endroll );

        animationEndrool = AnimationUtils.loadAnimation( this, R.anim.endrool );
        animationEndrool.setAnimationListener( animationListener_endrool );

        textView = (TextView)this.findViewById( R.id.textView );
        textView.startAnimation( animationEndrool );
    }

    ///    アニメーションリスナの登録
    private AnimationListener animationListener_endrool =
    new Animation.AnimationListener(){
        @Override
        public void onAnimationStart( Animation animation ){
            //    アニメーションの開始時
        }
        @Override
        public void onAnimationRepeat( Animation animation ){
            //    アニメーションの繰り返し時
        }
        @Override
        public void onAnimationEnd( Animation animation ){
            //    アニメーションの終了時
            finish(); // スケジュールされるだけ
        }
    };
}
textView の大きさがデバイスによって変わるため、スクロールテキストを調整する必要があります。

トラックバック

このエントリーのトラックバックURL:
https://www.remix.asia/cgi/mt/mt-tb.cgi/7513

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)