標籤:... bubuko pre getc 1.0 you roi rap tar
前些時候就是別人問我他的android APP怎麼做一個廣告的歡迎介面,就是過幾秒後自動跳轉到主介面的實現。
也就是下面這種類似的效果。要插什麼廣告的話你就換張圖吧。
那麼我就思考了下,就用了android 的一個動畫類Animation...其實在Android 的API開發文檔上就有的一個東西。自己可以去查下看。就像下面的這個圖上面的一樣的。也是屬於介面View 下的一個類方法...
其實這個東西,怎麼講呢。
咱主要的話還是來一個小白都看的懂的一個教程類的文章吧。
第一步的話
咱先開始在咱的項目中建立一個anim的檔案夾用來存等會要用到的一些 倒計時 的文字的動態效果的吧。(想想還是截個屏吧,怕有些同志還是看不懂...沒別的意思)
看到了麼,就是這樣的,在你的Android項目下的存放資源的那個檔案夾中建立一個anim檔案夾,再建立一個animation_text.xml
的xml檔案,待會就知道有啥用了。
咱下面
第二步的話,咱就開始新增內容了。
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <alpha 5 android:duration="1000" 6 android:fromAlpha="0.0" 7 android:toAlpha="1.0" /> 8 9 <scale10 android:duration="800"11 android:fromXScale="1.5"12 android:fromYScale="1.5"13 android:pivotX="50%"14 android:pivotY="50%"15 android:toXScale="1.0"16 android:toYScale="1.0" />17 18 </set>
上面的效果的話,如果是不知道這些屬性是什麼意思的話那你可以百度的,我這一一講的話就感覺有點囉嗦的了。
咱還是講正題吧,那上面這些寫的有什麼用呢。就看下面了,那麼我們下面就得開始把那個介面布局出來了吧,然後我們下面就開始吧,
做一個類似我上面的介面吧。咱就用FrameLayout布局了,如果知道是什麼布局方式的話,我覺得應該看的懂吧。
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="@drawable/page24" 6 tools:context="${relativePackage}.${activityClass}" > 7 8 <LinearLayout 9 android:layout_width="wrap_content"10 android:layout_height="wrap_content"11 android:layout_gravity="right"12 android:orientation="horizontal" >13 14 <TextView15 android:layout_width="wrap_content"16 android:layout_height="wrap_content"17 android:layout_gravity="right"18 android:text="廣告倒計時:"19 android:textColor="#ffffff"20 android:textSize="20sp" />21 22 <TextView23 android:id="@+id/textView"24 android:layout_width="wrap_content"25 android:layout_height="wrap_content"26 android:layout_gravity="right"27 android:text="5"28 android:textColor="#ffffff"29 android:textSize="20sp" />30 31 <TextView32 android:layout_width="wrap_content"33 android:layout_height="wrap_content"34 android:layout_gravity="right"35 android:text="s"36 android:textColor="#ffffff"37 android:textSize="20sp" />38 </LinearLayout>39 40 </FrameLayout>
下面的話咱就開始要寫怎麼在app內部實現的方法了吧,這就到了我們的Java的程式天地來了。
這時候我們就在項目下的src檔案下的包裡面寫上你的Java檔案吧。咱慢慢來,別急。
1 /** 2 * 3 * 1.聲明介面 4 * 2.定義變數 5 * 3.調用類Animation 6 * 4.寫方法讓它動起來 7 * @author Rain 8 * 9 */10 public class WelcomeActivity extends Activity{11 12 // 聲明控制項對象13 private TextView textView;14 //聲明時間有多少;15 private int count = 5;16 private Animation animation;17 18 @Override19 protected void onCreate(Bundle savedInstanceState) {20 super.onCreate(savedInstanceState);21 // 下面的話就是去除標題的方法22 requestWindowFeature(Window.FEATURE_NO_TITLE);23 setContentView(R.layout.activity_welcome);24 // 初始化控制項對象textView25 textView = (TextView) findViewById(R.id.textView);26 animation = AnimationUtils.loadAnimation(this, R.anim.animation_text);27 handler.sendEmptyMessageDelayed(0, 1000);28 29 30 }31 32 //咱在寫一個計算Welcome介面的廣告時間結束後進入主介面的方法33 private int getCount() {34 count--;35 if (count == 0) {36 Intent intent = new Intent(this, MainActivity.class);37 startActivity(intent);38 finish();39 }40 return count;41 }42 43 //進行一個訊息的處理44 @SuppressLint("HandlerLeak")45 private Handler handler = new Handler() {46 public void handleMessage(android.os.Message msg) {47 if (msg.what == 0) {48 textView.setText(getCount()+"");49 handler.sendEmptyMessageDelayed(0, 1000);50 animation.reset();51 textView.startAnimation(animation);52 }53 54 };55 56 };57 58 }
用的時候可得注意匯入下包哈。
這樣一個會自動跳轉到主介面的廣告介面就完成了。
謝謝觀看。大家可以暢所欲言,發表看法,吾等虛心接受的。
淺談Android的廣告歡迎介面(倒計時)