国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現閃屏效果

2019-10-21 21:48:12
字體:
來源:轉載
供稿:網友

在登陸一些頁面時,通常能看見“一閃而過”效果并進入頁面。下面看看是怎樣實現這樣的效果的吧

首先,在布局里(可以說和平常沒有什么不同),劃線部分是進度條:

<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"  android:background="@drawable/bg" >   <ImageView    android:id="@+id/welcome"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_centerHorizontal="true"    android:layout_marginBottom="45dp"    android:src="@drawable/welcome" />   <ProgressBar    android:id="@+id/progressBar"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_below="@+id/welcome"    android:layout_centerHorizontal="true"     android:layout_marginBottom="70dp"    />   <TextView    android:id="@+id/textView1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_below="@+id/progressBar"    android:layout_centerHorizontal="true"    android:padding="@dimen/padding_medium"    android:text="@string/welcome"    android:textAppearance="?android:attr/textAppearanceMedium"    tools:context=".MainActivity" /> </RelativeLayout>

在String中定義:

<resources>   <string name="app_name">ShanP01</string>  <string name="welcome">歡迎加入!/n一起快樂學習!</string>//(/n)實現換行  <string name="menu_settings">Settings</string>  <string name="title_activity_main">MainActivity</string>  <string name="title_study">學習</string>  <string name="title_search">搜查</string>  <string name="title_game">游戲</string>  <string name="title_save">保存</string>  <string name="title_help">幫助</string>  <string name="title_activity_welcome">WelcomeActivity</string> </resources>

如果想在運行項目時不顯示標題欄,則在想隱藏標題欄的Activity中加一句即可(在AndroidManifest.xml文件中):

android:theme="@android:style/Theme.NoTitleBar" 

最主要的實現方法:

 

public class WelcomeActivity extends Activity { private ImageView welcomeImage;    @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_welcome);    welcomeImage=(ImageView) this.findViewById(R.id.welcome);    AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f, 1.0f);////定義一個具有淡入效果的對象    alphaAnimation.setDuration(3000);//定義閃屏時間(毫秒)    welcomeImage.startAnimation(alphaAnimation);    alphaAnimation.setAnimationListener(new AnimationListener() {    @Override  public void onAnimationStart(Animation animation) {      }    @Override  public void onAnimationRepeat(Animation animation) {      }    @Override  public void onAnimationEnd(Animation animation) {  Intent intent=new Intent();  intent.setClass(WelcomeActivity.this, MainActivity.class);//定義閃屏效果從哪一界面跳到哪一頁面  startActivity(intent);  finish();    } });  }   @Override  public boolean onCreateOptionsMenu(Menu menu) {    getMenuInflater().inflate(R.menu.activity_welcome, menu);    return true;  }  }

其實閃屏效果不止這一種,但這是我認為簡便的一種。還有一種:

public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_welcome);     welcomeImage=(ImageView) this.findViewById(R.id.welcome);       AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);////定義1個具有淡入效果的對象     welcomeImage.startAnimation(alphaAnimation);     new Handler().postDelayed(new Runnable() {          @Override       public void run() {         Intent intent=new Intent();         intent.setClass(WelcomeActivity.this, MainActivity.class);         startActivity(intent);         finish();       }     },3000);//細心不要漏了   } 

你覺得哪一種更適合你呢?

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长治县| 清水河县| 修武县| 竹山县| 花莲县| 聂拉木县| 新野县| 隆尧县| 陆良县| 奎屯市| 关岭| 车致| 大荔县| 广昌县| 古田县| 抚远县| 江华| 榆林市| 庆安县| 黄石市| 绩溪县| 富宁县| 阜南县| 莱州市| 武汉市| 佛冈县| 新宁县| 威远县| 达州市| 长沙县| 莱阳市| 新巴尔虎左旗| 东光县| 偏关县| 延庆县| 城口县| 台北市| 东丰县| 宿松县| 宜丰县| 东丰县|