仿知乎日报第二篇:Splash页

一.

1.首先看效果:

 

2.实现起来很简单:

1)布局(splashlayout.xml)

2)代码(SplashActivity.java)

 

二.分析布局:


代码(splashlayout.xml):

<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <ImageView
       android:id="@+id/iv_spash_backgroud"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@drawable/splash"/>
    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="100dp"
       android:background="#44000000"
       android:layout_alignParentBottom="true"
       android:orientation="vertical"
       >
       
 
        <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="知乎日报"
           android:textColor="#FFFFFF"
           android:textSize="25sp"
           android:layout_marginLeft="30dp"
           android:layout_marginTop="15dp"/>
 
        <TextViewandroid:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="每天三次,每次七分中"
           android:textColor="#FFFFF0"
           android:textSize="18sp"
           android:layout_marginLeft="30dp"
           android:layout_marginTop="8dp"/>
     
    </LinearLayout>
 
</RelativeLayout>


 

.新建activity包专门放各种activity,并创建SplashActivity.java


 

1.SplashActivity中的逻辑

1) requestWindowFeature(Window.FEATURE_NO_TITLE)去除标题栏,这样就可以全屏显示了

2)加载splashlayout布局,拿到ImageView组件

3)在ImageView上启动Alpha动画,实现从无到有动画

4)动画完成,跳转到MainActivity

 

 

2.注意:

1)布局,组件的初始化全部放在initView()方法中。

2)事件的初始化全部放在initListener()方法中。

 

 

3.具体代码:

public class SplashActivity extends Activity {
    private View        mIvBackground;
    private AlphaAnimation  mAlphaAnimation;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // 1)去除标题栏,这样就可以全屏显示了
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       initView();
       // 初始化动画
       initAnimation();
       initListener();
 
    }
 
    private void initListener() {
       mAlphaAnimation.setAnimationListener(new AnimationListener() {
 
           @Override
           public void onAnimationStart(Animation arg0) {
 
           }
 
           @Override
           public void onAnimationRepeat(Animation arg0) {
 
           }
 
           /*
            * 4)动画完成,跳转到MainActivity
            */
           @Override
           public void onAnimationEnd(Animation arg0) {
             
              Intent intent = new Intent(SplashActivity.this,
                     MainActivity.class);
              startActivity(intent);
              finish();
           }
       });
    }
 
    /**
     * 3)在ImageView上启动Alpha动画,实现从无到有动画
     */
    private void initAnimation() {
       /*
        * AnimationSetanimationSet = new AnimationSet(true);
        *
        * ScaleAnimationscaleAnimation = new ScaleAnimation(0, 1, 0, 1,
        *Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        *scaleAnimation.setDuration(2000); scaleAnimation.setFillAfter(true);
        *animationSet.addAnimation(scaleAnimation);
        */
 
       mAlphaAnimation = new AlphaAnimation(0f, 1f);
       mAlphaAnimation.setDuration(1500);
       mAlphaAnimation.setFillAfter(true);
       //animationSet.addAnimation(alphaAnimation);
 
       mIvBackground.setAnimation(mAlphaAnimation);
    }
 
    /**
     * 2)加载splashlayout布局,拿到ImageView组件
     */
    private void initView() {
       setContentView(R.layout.splashlayout);
       mIvBackground = findViewById(R.id.iv_spash_backgroud);
 
    }
 
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值