闪屏
来源:互联网 发布:淘宝药店 提交需求 编辑:程序博客网 时间:2024/04/30 16:55
运行结果
GuideActivity.java
package com.example.flashscreendemo;import java.util.ArrayList;import java.util.List;import com.example.flashscreendemo.adapter.GuideAdapter;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.support.v4.view.ViewPager;import android.support.v4.view.ViewPager.OnPageChangeListener;import android.view.LayoutInflater;import android.view.Menu;import android.view.View;import android.widget.ImageView;public class GuideActivity extends Activity {private ViewPager vpGuide;private ImageView ivDots[];private int[] dots_id;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_guide);initGuideViews();initDots();vpGuide.setOnPageChangeListener(new OnPageChangeListener() {@Overridepublic void onPageSelected(int position) {for (int i = 0; i < ivDots.length; i++) {if (position == i) {ivDots[i].setImageResource(R.drawable.bg_point_selected);} else {ivDots[i].setImageResource(R.drawable.bg_point_normal);}}}@Overridepublic void onPageScrolled(int position, float arg1, int arg2) {}@Overridepublic void onPageScrollStateChanged(int postion) {}});}public void jumpMain(View view) {Intent intent = new Intent(this, MainActivity.class);startActivity(intent);finish();}private void initDots() {dots_id = new int[] { R.id.ivDots1, R.id.ivDots2, R.id.ivDots3,R.id.ivDots4 };ivDots = new ImageView[dots_id.length];for (int i = 0; i < ivDots.length; i++) {ivDots[i] = (ImageView) findViewById(dots_id[i]);}}private void initGuideViews() {vpGuide = (ViewPager) findViewById(R.id.vpGuide);List<View> views = new ArrayList<View>();LayoutInflater layoutInflater = getLayoutInflater();View view1 = layoutInflater.inflate(R.layout.view1ofpager, null);views.add(view1);View view2 = layoutInflater.inflate(R.layout.view2ofpager, null);views.add(view2);View view3 = layoutInflater.inflate(R.layout.view3ofpager, null);views.add(view3);View view4 = layoutInflater.inflate(R.layout.view4ofpager, null);views.add(view4);GuideAdapter guideAdapter = new GuideAdapter(views);vpGuide.setAdapter(guideAdapter);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.guide, menu);return true;}}
GuideAdapter.java
package com.example.flashscreendemo.adapter;import java.util.List;import android.support.v4.view.PagerAdapter;import android.view.View;import android.view.ViewGroup;public class GuideAdapter extends PagerAdapter{ private List<View> views; public GuideAdapter(List<View> views) {super();this.views = views;}@Overridepublic int getCount() {return views.size();}@Overridepublic boolean isViewFromObject(View view, Object object) {return view==object;}@Overridepublic Object instantiateItem(ViewGroup container, int position) {container.addView(views.get(position));return views.get(position);}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {container.removeView(views.get(position));}}
WeclomeActivity.java
package com.example.flashscreendemo;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.Animation.AnimationListener;import android.view.animation.RotateAnimation;import android.widget.ImageView;import android.widget.RelativeLayout;public class WeclomeActivity extends Activity{ private RelativeLayout layoutWecome; private ImageView ivMonkey;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);/*requestWindowFeature(Window.FEATURE_NO_TITLE);//取消电量状态栏this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);*/setContentView(R.layout.activity_weclome);layoutWecome=(RelativeLayout) findViewById(R.id.layoutWelcome);AlphaAnimation alphaAnimation=new AlphaAnimation(0.0f, 1.0f);alphaAnimation.setDuration(1000);layoutWecome.startAnimation(alphaAnimation);ivMonkey=(ImageView) findViewById(R.id.ivMonkey);RotateAnimation rotateAnimation=new RotateAnimation(0,360);rotateAnimation.setDuration(1000);rotateAnimation.setRepeatCount(2);ivMonkey.startAnimation(rotateAnimation);rotateAnimation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {Intent intent=new Intent(WeclomeActivity.this,GuideActivity.class);startActivity(intent);finish();}});}}
activity_guide.xml
<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=".GuideActivity" > <android.support.v4.view.ViewPager android:id="@+id/vpGuide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" > </android.support.v4.view.ViewPager> <LinearLayout android:id="@+id/layoutDots" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:gravity="center_horizontal" android:layout_marginBottom="30dp" android:orientation="horizontal" > <ImageView android:id="@+id/ivDots1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg_point_selected" /> <ImageView android:id="@+id/ivDots2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/bg_point_normal" /> <ImageView android:id="@+id/ivDots3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/bg_point_normal" /> <ImageView android:id="@+id/ivDots4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@drawable/bg_point_normal" /> </LinearLayout></RelativeLayout>
view4ofpager.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/guide_1" android:orientation="vertical" > <TextView android:id="@+id/tvGo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_marginBottom="46dp" android:background="@drawable/start_select" android:clickable="true" android:gravity="center" android:onClick="jumpMain" android:text="Go" android:textColor="#ffffff" android:textSize="30sp" /></RelativeLayout>
0 0
- 闪屏
- Java闪屏
- Swing 闪屏
- vc 闪屏
- andoird闪屏
- Android 闪屏
- android 闪屏
- Ubuntu闪屏
- 3、闪屏
- Cordova 闪屏
- 显示一个WinForms闪屏
- Android 2.1 闪屏
- j2se闪屏splash方法
- Andriod Splash闪屏
- cocos2dx调用android闪屏
- theme style 闪屏
- 闪屏(Splash)
- 7walker闪屏
- IoC容器笔记2
- Android自定义View入门级
- docker相关技术
- Prime Ring Problem
- python学习_基础(一)
- 闪屏
- MySQL存储过程学习
- 系统tcp 连接状态统计
- POJ 3050 Hopscotch 笔记
- hive udf
- AT&T汇编mov和movl同时使用
- 聂树斌案再审改判无罪 国家赔偿
- 安卓在代码中给button添加和设置图片
- mysql主从复制配置(基于日志点)