今天实现效果如下
目标实现:
1.开始动画,欢迎界面 done
2.初始导航 done
3.版本信息没做。。。
每个应用在第一打开时都有个欢迎动画,那我们今天就来实现它
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.safephone.WelcomeMainActivity" >
<ImageView
android:id="@+id/welcome_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:src="@drawable/ic_sheep" />
</RelativeLayout>
目标:边旋转边放大
有三个动画 旋转0-360 缩放0-1 透明度 0-1
public class WelcomeMainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) findViewById(R.id.welcome_iv);
/**
* animation conbine
*/
AnimationSet set = new AnimationSet(false);
// 边旋转边放大
RotateAnimation rotateAnimation = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(3000);// 设置时间为两秒
rotateAnimation.setFillAfter(true);// 设置最终状态为填充效果
set.addAnimation(rotateAnimation);// 将旋转动画添加到动画集合中
/**
*
*/
ScaleAnimation scaleAnimation=new ScaleAnimation(
0, 1,
0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(3000);//
rotateAnimation.setFillAfter(true);// 设置最终状态为填充效果
set.addAnimation(scaleAnimation);// 将缩放动画添加到动画集合中
/**
* 第三个动画来自xml
*/
Animation animation=AnimationUtils.loadAnimation(this, R.anim.alpha);
set.addAnimation(animation);// 将透明度动画添加到动画集合中
set.setAnimationListener(new AnimationListener() {
//begin
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
//repeat
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
//end
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
ToastUtils.show(getApplicationContext(), "欢迎来到德莱联盟");
//the animation end enter the guideActivity
Intent intent=new Intent();
intent.setClass(getApplicationContext(), GuideActivity.class);
startActivity(intent);
finish();
}
});
imageView.startAnimation(set);
}
}
效果如下
主要代码
public class ActivityGuide extends Activity {
private List<ImageView> mPageList;
private Context context;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.guidelayout);
ViewPager mGuideViewPager = (ViewPager) findViewById(R.id.viewpager);
btn = (Button) findViewById(R.id.guide_enter_btn);
// page list
context = this;
// init page
initpage();
// 2.initdata by adapter
mGuideViewPager.setAdapter(new PagerAdapter() {
// is the view from object or from fragment
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0 == arg1;
}
// view items count
@Override
public int getCount() {
// TODO Auto-generated method stub
return mPageList == null ? 0 : mPageList.size();
}
// DESTORY the view items
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// TODO Auto-generated method stub
container.removeView(mPageList.get(position));
}
/**
* init view items pass position container ViewGroup ViewPager
*/
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
container.addView(mPageList.get(position));
return mPageList.get(position);
}
});
// 3、对viewpage进行监听
mGuideViewPager.addOnPageChangeListener(new OnPageChangeListener() {
//当页面被选择则回调该方法
@Override
public void onPageSelected(int position) {
if(position==(mPageList.size()-1)){
btn.setVisibility(View.VISIBLE);
}else{
btn.setVisibility(View.GONE);
}
}
//页面滚动回调该方法
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
//当页面滚动状态改变
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
//
private void initpage() {
// TODO Auto-generated method stub
mPageList = new ArrayList<ImageView>();
ImageView imageView = new ImageView(context);
imageView.setBackgroundResource(R.drawable.guide_1);
mPageList.add(imageView);
ImageView imageView2 = new ImageView(context);
imageView2.setBackgroundResource(R.drawable.guide_2);
mPageList.add(imageView2);
ImageView imageView3 = new ImageView(context);
imageView3.setBackgroundResource(R.drawable.guide_3);
mPageList.add(imageView3);
}
public void entersystem(View view) {
Intent intent = new Intent(this, SplashActivity.class);
startActivity(intent);
finish();
}
}
Viewpage是viewgroup的子类
能实现水平的滑动效果
来看布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" >
<!-- ViewPager -->
<android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" />
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBottom="@id/viewpager" android:background="#44000000" android:gravity="center" android:orientation="vertical" android:padding="5dip" >
<!-- Banner的文字描述 -->
<TextView android:id="@+id/tv_banner_text_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/white" />
<!-- 小圆点的父控件 -->
<LinearLayout android:id="@+id/ll_dot_group" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="5dip" android:gravity="center_horizontal" android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
<Button android:id="@+id/guide_enter_btn" android:layout_width="135dp" android:layout_height="45dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:gravity="center" android:visibility="gone" android:onClick="entersystem" android:background="@drawable/guide_btn_seletor" android:textColor="@color/guide_btn_color_seletor" android:layout_marginBottom="55dp" android:text="开始体验" />
</RelativeLayout>
毕竟是项目 细节不是太好说的清楚,主要是看大概然后跟着流程一步一步来