仿知乎日报第二篇:Splash页
来源:互联网 发布:淘宝如何排名靠前 编辑:程序博客网 时间:2024/06/12 01:14
一.
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 0
- 仿知乎日报第二篇:Splash页
- 【1】知乎日报---Splash页面开发
- 第二章 第六节 绘制Splash Screens
- 引导页splash
- splash
- splash
- Splash
- 高效启动页(Splash)
- Android引导页Splash设计
- 仿知乎日报android
- 仿知乎日报前言
- 仿知乎日报2.64版本
- 日报
- 日报
- 日报
- 日报
- 【iOS】仿知乎日报,RxSwift-Part2-详情页的搭建
- 仿知乎日报第三篇:MainActivity的布局分析
- socket编程 - Asyncsocket
- maven部署jar 到远程仓库
- 用ABAP来实现柱状图和饼状图的输出
- 利用svn log命令实现的资源版本更新
- UIScrollView
- 仿知乎日报第二篇:Splash页
- PY爬虫专用导航贴
- php底层原理之PHP变量的存储
- Gitlib 添加SSH KEY
- 第一章 TCP/IP协议族
- 汉字转拼音和简拼工具类分享
- Linux IO实时监控iostat命令详解
- linux内核中读写用户态文件
- NOIP提高组【JZOJ4787】数格子