Android 實(shí)現(xiàn)廣告歡迎界面(倒計(jì)時(shí))
前些時(shí)候就是別人問(wèn)我他的android APP怎么做一個(gè)廣告的歡迎界面,就是過(guò)幾秒后自動(dòng)跳轉(zhuǎn)到主界面的實(shí)現(xiàn)。
也就是下面這種類(lèi)似的效果。要插什么廣告的話(huà)你就換張圖吧。

那么我就思考了下,就用了android 的一個(gè)動(dòng)畫(huà)類(lèi)Animation...其實(shí)在Android 的API開(kāi)發(fā)文檔上就有的一個(gè)東西。自己可以去查下看。就像下面的這個(gè)圖上面的一樣的。也是屬于界面View 下的一個(gè)類(lèi)方法...

其實(shí)這個(gè)東西,怎么講呢。
咱主要的話(huà)還是來(lái)一個(gè)小白都看的懂的一個(gè)教程類(lèi)的文章吧。
第一步的話(huà)
咱先開(kāi)始在咱的項(xiàng)目中新建一個(gè)anim的文件夾用來(lái)存等會(huì)要用到的一些 倒計(jì)時(shí) 的文字的動(dòng)態(tài)效果的吧。(想想還是截個(gè)屏吧,怕有些同志還是看不懂...沒(méi)別的意思)
看到了么
看到了么,就是這樣的,在你的Android項(xiàng)目下的存放資源的那個(gè)文件夾中新建一個(gè)anim文件夾,再新建一個(gè)animation_text.xml
的xml文件,待會(huì)就知道有啥用了。
咱下面
第二步的話(huà),咱就開(kāi)始添加內(nèi)容了。
<?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>
上面的效果的話(huà),如果是不知道這些屬性是什么意思的話(huà)那你可以百度的,我這一一講的話(huà)就感覺(jué)有點(diǎn)啰嗦的了。
咱還是講正題吧,那上面這些寫(xiě)的有什么用呢。就看下面了,那么我們下面就得開(kāi)始把那個(gè)界面布局出來(lái)了吧,然后我們下面就開(kāi)始吧,
做一個(gè)類(lèi)似我上面的界面吧。咱就用FrameLayout布局了,如果知道是什么布局方式的話(huà),我覺(jué)得應(yīng)該看的懂吧。
<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"
android:background="@drawable/page24"
tools:context="${relativePackage}.${activityClass}" >
<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="廣告倒計(jì)時(shí):"
android:textColor="#ffffff"
android:textSize="20sp" />
<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="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="s"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
</FrameLayout>
下面的話(huà)咱就開(kāi)始要寫(xiě)怎么在app內(nèi)部實(shí)現(xiàn)的方法了吧,這就到了我們的Java的程序天地來(lái)了。
這時(shí)候我們就在項(xiàng)目下的src文件下的包里面寫(xiě)上你的Java文件吧。咱慢慢來(lái),別急。
/**
*
* 1.聲明界面
* 2.定義變量
* 3.調(diào)用類(lèi)Animation
* 4.寫(xiě)方法讓它動(dòng)起來(lái)
* @author Rain
*
*/
public class WelcomeActivity extends Activity{
// 聲明控件對(duì)象
private TextView textView;
//聲明時(shí)間有多少;
private int count = 5;
private Animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 下面的話(huà)就是去除標(biāo)題的方法
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_welcome);
// 初始化控件對(duì)象textView
textView = (TextView) findViewById(R.id.textView);
animation = AnimationUtils.loadAnimation(this, R.anim.animation_text);
handler.sendEmptyMessageDelayed(0, 1000);
}
//咱在寫(xiě)一個(gè)計(jì)算Welcome界面的廣告時(shí)間結(jié)束后進(jìn)入主界面的方法
private int getCount() {
count--;
if (count == 0) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
return count;
}
//進(jìn)行一個(gè)消息的處理
@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);
}
};
};
}
用的時(shí)候可得注意導(dǎo)入下包哈。
這樣一個(gè)會(huì)自動(dòng)跳轉(zhuǎn)到主界面的廣告界面就完成了。
總結(jié)
以上所述是小編給大家介紹的Android 實(shí)現(xiàn)廣告歡迎界面(倒計(jì)時(shí)),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android使用ViewPager實(shí)現(xiàn)滾動(dòng)廣告
- Android 知乎廣告效果實(shí)現(xiàn)代碼
- Android開(kāi)發(fā)實(shí)現(xiàn)廣告無(wú)限循環(huán)功能示例
- Android滾動(dòng)條廣告實(shí)現(xiàn)代碼示例
- Android ViewPager實(shí)現(xiàn)無(wú)限循環(huán)輪播廣告位Banner效果
- Android 應(yīng)用啟動(dòng)歡迎界面廣告的實(shí)現(xiàn)實(shí)例
- Android仿淘寶頭條向上滾動(dòng)廣告條ViewFlipper
- Kotlin FrameLayout與ViewPager2控件實(shí)現(xiàn)滾動(dòng)廣告欄方法
相關(guān)文章
深入解析Android系統(tǒng)中應(yīng)用程序前后臺(tái)切換的實(shí)現(xiàn)要點(diǎn)
這篇文章主要介紹了Android系統(tǒng)中應(yīng)用程序前后臺(tái)切換的實(shí)現(xiàn)要點(diǎn),除了切換操作的效果之外還重點(diǎn)講解了判斷程序運(yùn)行于前臺(tái)還是后臺(tái)的方法,需要的朋友可以參考下2016-04-04
詳解Flutter?響應(yīng)式狀態(tài)管理框架GetX
這篇文章主要為大家介紹了Flutter?響應(yīng)式狀態(tài)管理框架GetX詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Android網(wǎng)絡(luò)請(qǐng)求框架Retrofit詳解
這篇文章主要為大家詳細(xì)介紹了Android網(wǎng)絡(luò)請(qǐng)求框架Retrofit,使用Retrofit2.0.0版本進(jìn)行實(shí)例演示,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
android書(shū)架效果實(shí)現(xiàn)原理與代碼
以前也模仿者ireader實(shí)現(xiàn)了書(shū)架的效果,但是那種是使用listview實(shí)現(xiàn)的,并不好用,今天介紹android書(shū)架效果實(shí)現(xiàn)方法2013-01-01
Android 實(shí)時(shí)監(jiān)測(cè)(監(jiān)聽(tīng))網(wǎng)絡(luò)連接狀態(tài)變化
這篇文章主要介紹了Android 實(shí)時(shí)監(jiān)測(cè)(監(jiān)聽(tīng))網(wǎng)絡(luò)連接狀態(tài)變化的相關(guān)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06
Android App在ViewPager中使用Fragment的實(shí)例講解
這篇文章主要介紹了Android App在ViewPager中使用Fragment的實(shí)例講解,ViewPager組件主要被用來(lái)制作滑動(dòng)切換效果,需要的朋友可以參考下2016-03-03

