功能:
左右滑动的广告
使用说明:
这次使用:android.support.v4.view 来实现左右滑动。
这次简单实现了网易广告左右滑动效果。欢迎大家一起来学习讨论!!!
先看图吧,有图有真相!!!
接下来看看代码:
界面Activity:
package com.bbswp.netnews;
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;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends Activity {
private ViewGroup mMainView = null;
private ViewPager mViewPager;
private ImageView[] mImageCircleViews;
private ViewGroup mImageCircleView = null;
private SlideImageLayout mSlideLayout;
private ArrayList<View> mImagePageViewList;
private TextView mSlideTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = getLayoutInflater();
mMainView = (ViewGroup) inflater.inflate(R.layout.activity_main, null);
mViewPager = (ViewPager) mMainView.findViewById(R.id.image_slide_page);
mSlideLayout = new SlideImageLayout(this.getApplicationContext());
int length = DataRes.slideImages.length;
mImageCircleViews = new ImageView[length];
mImageCircleView = (ViewGroup) mMainView.findViewById(R.id.layout_circle_images);
mSlideLayout.setCircleImageLayout(length);
mImagePageViewList = new ArrayList<View>();
for (int i = 0; i < length; i++) {
mImagePageViewList.add(mSlideLayout.getSlideImageLayout(DataRes.slideImages[i]));
mImageCircleViews[i] = mSlideLayout.getCircleImageLayout(i);
mImageCircleView.addView(mSlideLayout.getLinearLayout(mImageCircleViews