zoukankan      html  css  js  c++  java
  • Adroid ViewPage+GridView实现每页6个元素,三页滑动切换

    //}
    //public class MainActivity extends Activity {
    // private static final float APP_PAGE_SIZE = 16.0f;
    // private MyViewPagerAdapter adapter;
    // private ArrayListarray;
    // private ViewPager viewPager;
    // @Override
    // protected void onCreate(Bundle savedInstanceState) {
    // super.onCreate(savedInstanceState);
    // setContentView(R.layout.activity_main);
    // initViews();
    // viewPager = (ViewPager)findViewById(R.id.myviewpager);
    // adapter = new MyViewPagerAdapter(this, array);
    // viewPager.setAdapter(adapter);
    // }
    //
    // public void initViews() {
    // final PackageManager packageManager = getPackageManager();
    // final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    // mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    // // get all apps
    // final List apps = packageManager.queryIntentActivities(mainIntent, 0);
    // // the total pages
    // final int PageCount = (int)Math.ceil(apps.size()/APP_PAGE_SIZE);
    // array = new ArrayList();
    // for (int i=0; i
    // GridView appPage = new GridView(this);
    // appPage.setAdapter(new AppAdapter(this, apps, i));
    // appPage.setNumColumns(4);
    // array.add(appPage);
    // }
    //}


    /****************************************************************************************************************************/
    //
    // private static final String TAG = "GridViewPagerAdapter";
    // HomepageListModel.BookArray bookArray;
    // private Context context;
    // private LayoutInflater inflater;
    // TrackPresenter trackPresenter;
    // int index = 0;
    //
    // public GridViewPagerAdapter(Context context, HomepageListModel.BookArray bookArray) {
    // this.bookArray = bookArray;
    // this.context = context;
    // inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // this.trackPresenter = new TrackPresenter();
    // }
    //
    // /***
    // * 获取滑动的控件数量
    // * @return
    // */
    // @Override
    // public int getCount() {
    // return bookArray.books.size() % 6 == 0 ? bookArray.books.size() / 6 : (bookArray.books.size() / 6 + 1);
    // }
    //
    //
    // /***
    // * 判断是否显示的控件是否是一同个图片,这里将两个参数比较返回即可。
    // * @param view
    // * @param object
    // * @return
    // */
    // @Override
    // public boolean isViewFromObject(View view, Object object) {
    // return view == object;
    // }
    //
    // /***
    // * PagerAdapter只缓存三张要显示的图片,如果滑动的图片超出了缓存的范围,就会调用这个方法,将图片销毁
    // * @param container
    // * @param position
    // * @param object
    // */
    // @Override
    // public void destroyItem(ViewGroup container, int position, Object object) {
    // container.removeView(container.getRootView());
    // }
    //
    //
    // @Override
    // public Object instantiateItem(ViewGroup container, int position) {
    // View contentView = inflater.inflate(R.layout.gridview_root, null);
    // GridView gridviewRoot = (GridView) contentView.findViewById(R.id.grid_view);
    // gridviewRoot.setAdapter(new GridViewAdapter(bookArray, position));
    //
    // ((ViewPager) container).addView(contentView);
    // return contentView;
    // }
    //
    //
    // class GridViewAdapter extends BaseAdapter {
    //
    // ArrayList<HomepageListModel.Book> bookList;
    //
    // private int psition;
    //
    //
    //
    // public GridViewAdapter(HomepageListModel.BookArray bookArray, int position) {
    // this.bookList = bookArray.books;
    // this.psition = position;
    // }
    //
    // @Override
    // public int getCount() {
    // int page = bookList.size() % 6 == 0 ? bookList.size() / 6 : (bookList
    // .size() / 6 + 1);
    // if ((page - 1) > psition) {
    // return 6;
    // } else if (bookList.size() % 6 == 0) {
    // return 6;
    // } else {
    // return bookList.size() % 6;
    // }
    // }
    //
    // @Override
    // public Object getItem(int position) {
    // return bookList.get(position);
    // }
    //
    // @Override
    // public long getItemId(int position) {
    // return position;
    // }
    //
    // @Override
    // public View getView(final int position, View convertView, ViewGroup parent) {
    // GridItemViewHolder viewHolder = null;
    // if (convertView == null) {
    // viewHolder = new GridItemViewHolder();
    // convertView = inflater.inflate(R.layout.grid_view_item, null);
    //
    // convertView.setTag(viewHolder);
    // } else {
    // viewHolder = (GridItemViewHolder) convertView.getTag();
    // }
    //
    // viewHolder.linearLayout = (LinearLayout) convertView.findViewById(R.id.item_grid_linear);
    // viewHolder.imageView = (ImageView) convertView.findViewById(R.id.item_grid_img);
    // viewHolder.textName = (TextView) convertView.findViewById(R.id.item_grid_name_tv);
    // viewHolder.textAuthor = (TextView) convertView.findViewById(R.id.item_grid_author_tv);
    //
    // PicassoUtils.loadBookPic(context, bookList.get(index).bookThumb, viewHolder.imageView);
    //
    // viewHolder.textName.setText(bookList.get(index).bookTitle);
    // viewHolder.textAuthor.setText(bookList.get(index).bookAuthor);
    //
    // viewHolder.linearLayout.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View v) {
    // trackPresenter.updateModel(context, bookList.get(index).jTrackParams);
    // MyApp.getApp().startBookDetail(context, bookList.get(index).bookId);
    // }
    // });
    //
    // index++;
    //
    // //打印数据
    // BKLog.e(TAG, "---" + index);
    // return convertView;
    // }
    // }
    //
    // static class GridItemViewHolder {
    // ImageView imageView;
    // TextView textName;
    // TextView textAuthor;
    // LinearLayout linearLayout;
    // }
  • 相关阅读:
    How to become a hacker
    逻辑地址、线性地址、物理地址和虚拟地址
    java configuration
    Java 理论与实践: 变还是不变?
    Teach Yourself Programming in Ten Years
    border padding margin , the difference among them
    hashCode方法,equals方法,HashSet,HasMap之间的关系
    工程名 显示红色叹号
    记The_C_Programming_Language的错误
    VIM简单介绍学习1
  • 原文地址:https://www.cnblogs.com/lenkevin/p/8177924.html
Copyright © 2011-2022 走看看