-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>
請建議執行動畫的方式
當頁面加載,而不是點擊圖像時。
它顯示上下文的錯誤。 –
現在工作正常。非常感謝....使用這個--->上下文context = this;對於上下文錯誤... –
您的歡迎。 :)請投票它,如果它可以幫助你,並接受答案:) –