2016-09-26 6 views
-4

SplashActivity.javaクリックしないでスプラッシュ画面イメージの点滅を実装する方法は?

public class SplashActivity extends AppCompatActivity { 

    private static int SPLASH_TIME_OUT = 3000; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_splash); 
     ImageView imageView = (ImageView) findViewById(R.id.imageView); 
     imageView.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       blink(v); 
       //I am calling the animation only when the image is clicked. 
       //I want to perform animation as the page loads. 
       //Not on clicking the image. 
      } 

     }); 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       Intent i = new Intent(SplashActivity.this, LoginOptionsActivity.class); 
       startActivity(i); 
       finish(); 
      } 
     }, SPLASH_TIME_OUT); 
    } 

    public void blink(View view){ 
     ImageView image = (ImageView)findViewById(R.id.imageView); 
     Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink); 
     image.startAnimation(animation1); 
    } 
} 

blink.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<alpha android:fromAlpha="0.0" 
    android:toAlpha="1.0" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:duration="600" 
    android:repeatMode="reverse" 
    android:repeatCount="infinite"/> 
</set> 

activity_splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.codeinks.luxehues.SplashActivity" 
    android:background="@drawable/splash_shirt"> 
<ImageView 
    android:layout_width="300dp" 
    android:layout_height="150dp" 
    android:id="@+id/imageView" 
    android:src="@drawable/fullsize" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

アニメーションを実行する方法を提案してください

画像をクリックしている間ではなくページが読み込まれます。

答えて

0

onCreate方法でこれを試してみて、そのonClick方法をコメントすると、コードの下にコードの下

ImageView imageView = (ImageView) findViewById(R.id.imageView); 
Animation myAnim = AnimationUtils.loadAnimation(context,R.anim.blink); 
imageView.startAnimation(myAnim); 
+0

コンテキストのエラーを示します。 –

+0

これで問題なく動作します。ありがとうございました....これを使用--->コンテキストコンテキスト= this;文脈のエラーのため... –

+0

あなたの歓迎。 :)それがあなたを助け、答えを受け入れるならば投票してください:) –

0

てみ試してみる:

Thread splashTread; 

public void onAttachedToWindow() { 
    super.onAttachedToWindow(); 
    Window window = getWindow(); 
    window.setFormat(PixelFormat.RGBA_8888); 
} 

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

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
} 

private void StartAnimations() { 
    Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); 
    anim.reset(); 
    LinearLayout l = (LinearLayout) findViewById(R.id.layoutAnimation); 
    l.clearAnimation(); 
    l.startAnimation(anim); 

    anim = AnimationUtils.loadAnimation(this, R.anim.blink); 
    anim.reset(); 
    ImageView iv = (ImageView) findViewById(R.id.imageSplash); 
    iv.clearAnimation(); 
    iv.startAnimation(anim); 

    splashTread = new Thread() { 
     @Override 
     public void run() { 
      try { 
       int waited = 0; 
       // Splash screen pause time 
       while (waited < 3000) { 
        sleep(100); 
        waited += 100; 
       } 
       Intent intent = new Intent(SplashActivity.this, StartActivity.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
       startActivity(intent); 
      } catch (InterruptedException e) { 
       // do nothing 
      } finally { 
       SplashActivity.this.finish(); 
      } 
     } 
    }; 
    splashTread.start(); 
} 

と対応するXMLレイアウトは次のとおりです。

<!-- activity_splash.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:id="@+id/layoutAnimation" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".activities.SplashActivity"> 

    <ImageView 
     android:id="@+id/imageSplash" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:contentDescription="@string/splash" 
     android:scaleType="fitXY" 
     android:src="@drawable/splash" /> 

</LinearLayout> 

問題がある場合、plzは私を悩まします。あなたが助けてくれると思っています。

関連する問題