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)文章
Flutter開(kāi)發(fā)之動(dòng)態(tài)權(quán)限的使用
眾所周知,Android在6.0版本后將權(quán)限修改成了動(dòng)態(tài)權(quán)限,而iOS則一直使用的是動(dòng)態(tài)權(quán)限,所以在Flutter應(yīng)用開(kāi)發(fā)中如果涉及到一些危險(xiǎn)權(quán)限,就需要進(jìn)行動(dòng)態(tài)申請(qǐng),本文就詳細(xì)的介紹一下,感興趣的可以了解一下2021-09-09
Android自定義Spinner下拉列表(使用ArrayAdapter和自定義Adapter實(shí)現(xiàn))
這篇文章主要介紹了Android自定義Spinner下拉列表(使用ArrayAdapter和自定義Adapter實(shí)現(xiàn))的相關(guān)資料,需要的朋友可以參考下2015-10-10
Android為應(yīng)用添加數(shù)字角標(biāo)的簡(jiǎn)單實(shí)現(xiàn)
應(yīng)用的角標(biāo)是用來(lái)標(biāo)記有多少條提醒沒(méi)讀,本篇文章主要介紹了Android為應(yīng)用添加角標(biāo)的簡(jiǎn)單實(shí)現(xiàn),有興趣的可以了解一下。2017-04-04
Android中Fragment子類(lèi)及其PreferenceFragment的創(chuàng)建過(guò)程演示
這篇文章主要介紹了Android中Fragment子類(lèi)及其PreferenceFragment的創(chuàng)建過(guò)程演示,PreferenceFragment用來(lái)保存Fragment的選項(xiàng)設(shè)置,需要的朋友可以參考下2016-05-05
Android實(shí)現(xiàn)簡(jiǎn)單QQ登錄頁(yè)面
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單QQ登錄頁(yè)面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Android入門(mén)之ActivityGroup+GridView實(shí)現(xiàn)Tab分頁(yè)標(biāo)簽的方法
這篇文章主要介紹了Android入門(mén)之ActivityGroup+GridView實(shí)現(xiàn)Tab分頁(yè)標(biāo)簽的方法,非常實(shí)用的功能,需要的朋友可以參考下2014-08-08
Android getActivity()為空的問(wèn)題解決辦法
這篇文章主要介紹了Android getActivity()為空的問(wèn)題解決辦法的相關(guān)資料,導(dǎo)致apk空指針崩潰問(wèn)題,很?chē)?yán)重的問(wèn)題,為了解決這問(wèn)題,上網(wǎng)搜索了很多資料,需要的朋友可以參考下2017-07-07

