你好,游客 登录 注册 搜索
背景:
阅读新闻

Android实现图书的翻页效果

[日期:2011-09-21] 来源:Linux社区  作者:jianchibuxie5 [字体:大 中 小]

Android

程序代码结构如下:

 

MainActivity程序的入口类,BookLayout自定义布局,填充MainActivity。BookAdapter是BookLayout的Adapter,主要用来定义Layout中子View,我这里用的ImageView。

MainActivity代码:

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         BookLayout bk = new BookLayout(this);
        List<Integer> str = new ArrayList<Integer>();

         str.add(R.drawable.tiankong);
         str.add(R.drawable.qian);
         str.add(R.drawable.haer);
         str.add(R.drawable.gong);
        
         BookAdapter ba = new BookAdapter(this);
         ba.addItem(str);
         bk.setPageAdapter(ba);
         setContentView(bk);
    }
}

将资源包中4张Image的id放到List中。

BookAdapter主要方法如下:

public View getView(int position) {
   
    ImageView imageView = new ImageView(mContext);
    imageView.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    imageView.setImageResource(strList.get(position));
    return imageView;
}

这里定义imageView。

BookLayout,继承FrameLayout,主要用来实现图片的翻页效果。代码过多,这里不做解释。其中涉及到的Path知识见Android中Path的使用,涉及到Matrix的知识见Android利用Matrix简单处理图片。

linux
相关资讯       Android开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款