android启动时的广告

花门楼前见秋草,岂能贫贱相看老。这篇文章主要讲述android启动时的广告相关的知识,希望能为你提供帮助。
1.新建welecomeactivity.java

android启动时的广告

文章图片
android启动时的广告

文章图片
package com.example.dell.apps; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.TextView; import com.example.dell.apps.MainActivity; import com.example.dell.apps.R; public class WelcomeActivity extends Activity { // 声明控件对象 private TextView textView; //声明时间有多少; private int count = 5; private Animation animation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 下面的话就是去除标题的方法 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_welcome); // 初始化控件对象textView textView = (TextView) findViewById(R.id.textView); animation = AnimationUtils.loadAnimation(this, R.anim.animation_text); handler.sendEmptyMessageDelayed(0, 1000); } //咱在写一个计算Welcome界面的广告时间结束后进入主界面的方法 private int getCount() { count--; if (count == 0) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } return count; } //进行一个消息的处理 @SuppressLint("HandlerLeak") private Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { if (msg.what == 0) { textView.setText(getCount()+""); handler.sendEmptyMessageDelayed(0, 1000); animation.reset(); textView.startAnimation(animation); } }; }; }

View Code2.在res目录下新建anim文件夹,文件夹下新建animation_text.xml文件,文件中添加代码
android启动时的广告

文章图片
android启动时的广告

文章图片
< ?xml version="1.0" encoding="utf-8"?> < set xmlns:android="http://schemas.android.com/apk/res/android" > < alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" /> < scale android:duration="800" android:fromXScale="1.5" android:fromYScale="1.5" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.0" android:toYScale="1.0" /> < /set>

View Code3.在activity_welcome.xml文件中添加代码:
android启动时的广告

文章图片
android启动时的广告

文章图片
< FrameLayout 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"> < LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> < ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/welcome"/> //自己选择图片 < /LinearLayout> < LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:orientation="horizontal" > < TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="广告倒计时:" android:textColor="#ffffff" android:textSize="10sp" /> < TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="5" android:textColor="#ffffff" android:textSize="10sp" /> < TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="s" android:textColor="#ffffff" android:textSize="10sp" /> < /LinearLayout> < /FrameLayout>

View Codeps:Androidmanifest.xml中需注意:
android启动时的广告

文章图片
android启动时的广告

文章图片
< intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER" /> < /intent-filter>

View Code上述代码在哪个Activity中,哪个Activity就先启动
 
下面附上源码:https://pan.baidu.com/s/1pfYknrT9Vj3ocsk7zbT6Ww 
【android启动时的广告】提取密码:1psk

    推荐阅读