智慧北京开发第一天(上)
来源:互联网 发布:淘宝螺旋刷法 编辑:程序博客网 时间:2024/04/26 23:33
本应用采用Android Studio开发工具开发。
上午完成欢迎页和引导页:
运行效果:
代码实现:
欢迎页:
SplashActivity.java
package com.xbmu.wisdombj;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.widget.RelativeLayout;public class SplashActivity extends Activity { private RelativeLayout rlRoot; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); rlRoot = (RelativeLayout) findViewById(R.id.rl_Root); startAnimation(); } /** * 开启动画 */ private void startAnimation() { //RotateAnimation 旋转动画效果 RotateAnimation ra = new RotateAnimation(0f, 360f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); ra.setDuration(2000);//动画执行时间 ra.setFillAfter(true);//动画执行完后保持最终状态 //AlphaAnimation 透明度动画效果 AlphaAnimation aa = new AlphaAnimation(0f, 1f); aa.setDuration(2000); aa.setFillAfter(true); //ScaleAnimation 缩放动画效果 ScaleAnimation sa = new ScaleAnimation(0f, 1f, 0f, 1f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f); sa.setDuration(2000); sa.setFillAfter(true); //动画集合 AnimationSet set = new AnimationSet(false); set.addAnimation(ra); set.addAnimation(aa); set.addAnimation(sa); //设置动画的监听事件 set.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } /** * 动画结束 * @param animation */ @Override public void onAnimationEnd(Animation animation) { //跳转到引导界面 startActivity(new Intent(SplashActivity.this, GuideActivity.class)); finish();//结束当前页面 } @Override public void onAnimationRepeat(Animation animation) { } }); rlRoot.startAnimation(set); }}activity_splash.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_Root" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/splash_bg_newyear"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/splash_horse_newyear" /></RelativeLayout>
引导页:
GuideActivity.java
package com.xbmu.wisdombj;import android.app.Activity;import android.os.Bundle;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;import android.view.View;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.LinearLayout;import java.util.ArrayList;import java.util.List;public class GuideActivity extends Activity { private ViewPager vpGuide; private List<ImageView> imageViewList;//引导页的ImageView集合 private LinearLayout llPointGroup;//点的集合 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); vpGuide = (ViewPager) findViewById(R.id.vp_guide); llPointGroup = (LinearLayout) findViewById(R.id.ll_point_group); initViews(); //给ViewPager设置适配器 vpGuide.setAdapter(new GuideAdapter()); } /** * ViewPager的适配器 */ class GuideAdapter extends PagerAdapter { @Override public int getCount() { return imageViewList.size(); } @Override public Object instantiateItem(ViewGroup container, int position) { container.addView(imageViewList.get(position)); return imageViewList.get(position); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } } /** * 初始化界面 */ private void initViews() { imageViewList = new ArrayList<>(); //初始化引导页的3个页面 int[] idsImageView = new int[]{R.drawable.guide_1, R.drawable.guide_2, R.drawable.guide_3}; for (int i = 0; i < idsImageView.length; i++) { ImageView imageView = new ImageView(this); imageView.setBackgroundResource(idsImageView[i]);//设置引导页背景 imageViewList.add(imageView); //初始化引导页的小圆点 View point = new View(this); point.setBackgroundResource(R.drawable.guide_point_shape);//设置引导页默认圆点 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(10, 10);//设置圆点的大小 if (i > 0) { params.leftMargin = 10; } llPointGroup.addView(point, params);//将圆点添加到线性布局中 } }}activity_guide.xml
<?xml version="1.0" encoding="utf-8"?><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" tools:context="com.xbmu.wisdombj.GuideActivity"> <android.support.v4.view.ViewPager android:id="@+id/vp_guide" android:layout_width="match_parent" android:layout_height="match_parent" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="70dp" android:background="@drawable/btn_guide_selector" android:padding="5dp" android:text="开始体验" android:textColor="@drawable/btn_text_guide_selector" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="30dp"> <LinearLayout android:id="@+id/ll_point_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> </LinearLayout> <View android:layout_width="10dp" android:layout_height="10dp" android:background="@drawable/guide_red_point_shape"/> </RelativeLayout></RelativeLayout>btn_guide_selector.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_red_pressed"/> <item android:drawable="@drawable/button_red_normal"/></selector>btn_text_guide_selector.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="@android:color/black"/> <item android:color="@android:color/white"/></selector>guide_point_shape.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="@android:color/darker_gray"/></shape>guide_red_point_shape.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#f00"/></shape>
0 0
- 智慧北京开发第一天(上)
- 智慧北京开发第一天(下)
- 智慧北京开发第三天(上)
- 智慧北京开发第五天(上)
- 智慧北京项目第一天
- android项目智慧北京开发完整步骤:第一天
- 智慧北京开发第三天(中)
- 智慧北京开发第三天(下)
- 智慧北京开发第二天(上)
- 智慧北京开发第四天(上)
- 智慧北京第三天
- cocos2d_x游戏开发第一天(上)
- 智慧北京开发第二天(下)
- 智慧北京开发第四天(下)
- android项目智慧北京开发完整步骤:第三天
- 智慧北京第5天
- 智慧北京第6天
- 北京第一天
- Java中上传文件到服务器端
- 服务器搭建局域网访问
- PHP---语法笔记
- 23种设计模式(5):建造者模式
- java学习心得——navicat数据库的使用
- 智慧北京开发第一天(上)
- [Möbius]个人对Möbius反演的理解
- 失效模型定义
- 【慕课笔记】U3 继承 第3节 JAVA中的继承初始化顺序
- 基于MTD的NANDFLASH设备驱动底层实现原理分析(二)
- bzoj1500: [NOI2005]维修数列
- Android开发:LeakCanary--检测所有的内存泄漏
- 随机字符串
- 深入分析Java的序列化与反序列化