引导画面该如何才能较好的适配各种分辨率,了解此处有助于更好的定义引导画面,以及保持同设计师、工程师的良好沟通。.
android引导界面,实现了指示器的动画效果,不是固定在图片里面写死的。这样的用户体验更好。.
先看看效果图:
主要代码:
package com.example.introducedemo;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
private ImageView mImageView;
View mView;
private ArrayList<View> mPageViews;
// 定义LayoutInflater
LayoutInflater mInflater;
private ViewPager mViewPager;
LinearLayout mLinearLayout;
private ImageView[] mImageViews;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置窗口无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
mInflater = getLayoutInflater();
mPageViews = new ArrayList<View>();
mPageViews.add(mInflater.inflate(R.layout.view_01, null));
mPageViews.add(mInflater.inflate(R.layout.view_02, null));
mPageViews.add(mInflater.inflate(R.layout.view_03, null));
mImageViews = new ImageView[mPageViews.size()];
mView = mInflater.inflate(R.layout.activity_main, null);
mViewPager = (ViewPager) mView.findViewById(R.id.myviewpager);
mLinearLayout = (LinearLayout) mView
.findViewById(R.id.mybottomviewgroup);
for (int i = 0; i < mImageViews.length; i++) {
mImageView = new ImageView(MainActivity.this);
mImageView.setLayoutParams(new LayoutParams(10, 10));
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 0, 10, 0);
mImageView.setLayoutParams(lp);
if (i == 0) {
mImageView.setBackgroundResource(R.drawable.page_indicator_focused);
} else {
mImageView
.setBackgroundResource(R.drawable.page_indicator_unfocused);
}
mImageViews[i] = mImageView;
// 把指示作用的远点图片加入底部的视图中
mLinearLayout.addView(mImageViews[i]);
}
setContentView(mView);
mViewPager.setAdapter(new MyPagerAdapter());
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageSelected(int arg0) {
for (int i = 0; i < mImageViews.length; i++) {
if (i == arg0) {
mImageViews[i]
.setBackgroundResource(R.drawable.page_indicator_focused);
} else {
mImageViews[i]
.setBackgroundResource(R.drawable.page_indicator_unfocused);
}
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
class MyPagerAdapter extends PagerAdapter {
@Override
public int getCount() {
return mPageViews.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return super.getItemPosition(object);
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
// TODO Auto-generated method stub
((ViewPager) arg0).removeView(mPageViews.get(arg1));
}
@Override
public Object instantiateItem(View arg0, int arg1) {
// TODO Auto-generated method stub
((ViewPager) arg0).addView(mPageViews.get(arg1));
return mPageViews.get(arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
// TODO Auto-generated method stub
}
@Override
public Parcelable saveState() {
// TODO Auto-generated method stub
return null;
}
@Override
public void startUpdate(View arg0) {
// TODO Auto-generated method stub
}
@Override
public void finishUpdate(View arg0) {
// TODO Auto-generated method stub
}
}
}