阅读过电子书的朋友相信对iReader都是比较熟悉的,iReader的书架做的非常漂亮,以前总以为是使用了2D画图做的呢,今天反编译了一下才明白原来是用图片拼接起来的,这样就OK了,今天我就带大家实现一个iReader书架。

首先看一下layout下main.xml布局:

[html] view plaincopyprint?
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical" >
  6. <RelativeLayout
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"
  9. android:background="@drawable/bookshelf_header_bg" >
  10. <ImageView
  11. android:id="@+id/shelf_image_title"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:layout_centerInParent="true"
  15. android:background="@drawable/bookshelf_header_logo" />
  16. <Button
  17. android:id="@+id/shelf_image_button"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:layout_alignParentRight="true"
  21. android:background="@drawable/bookshelf_goto_bookcity_f" />
  22. </RelativeLayout>
  23. <ListView
  24. android:id="@+id/shelf_list"
  25. android:layout_width="fill_parent"
  26. android:layout_height="fill_parent"
  27. android:scrollbars="none"
  28. android:divider="#00000000"
  29. android:cacheColorHint="#00000000"/>
  30. </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bookshelf_header_bg" >
<ImageView
android:id="@+id/shelf_image_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/bookshelf_header_logo" />
<Button
android:id="@+id/shelf_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/bookshelf_goto_bookcity_f" />
</RelativeLayout>
<ListView
android:id="@+id/shelf_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:divider="#00000000"
android:cacheColorHint="#00000000"/>
</LinearLayout>

由于书架是用图片拼成的,所以每一个行的数据框都是一个listview ,  看一些listview对应的item布局:

[html] view plaincopyprint?
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent" >
  5. <ImageView
  6. android:id="@+id/shelf_image_left"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:layout_alignParentLeft="true"
  10. android:layout_centerVertical="true"
  11. android:background="@drawable/bookshelf_layer_left" />
  12. <LinearLayout
  13. android:id="@+id/linearLayout1"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_centerVertical="true"
  17. android:layout_toLeftOf="@+id/shelf_image_right"
  18. android:layout_toRightOf="@+id/shelf_image_left"
  19. android:background="@drawable/bookshelf_layer_center"
  20. android:orientation="horizontal" >
  21. <LinearLayout
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:layout_weight="1"
  25. android:gravity="center_horizontal" >
  26. <Button
  27. android:id="@+id/button_1"
  28. android:layout_width="80dip"
  29. android:layout_height="110dip"
  30. android:layout_marginTop="15dip"
  31. android:background="@drawable/default_cover" />
  32. </LinearLayout>
  33. <LinearLayout
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:layout_weight="1"
  37. android:gravity="center_horizontal" >
  38. <Button
  39. android:id="@+id/button_2"
  40. android:layout_width="80dip"
  41. android:layout_height="110dip"
  42. android:layout_marginTop="15dip"
  43. android:background="@drawable/default_cover" />
  44. </LinearLayout>
  45. <LinearLayout
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:layout_weight="1"
  49. android:gravity="center_horizontal" >
  50. <Button
  51. android:id="@+id/button_3"
  52. android:layout_width="80dip"
  53. android:layout_height="110dip"
  54. android:layout_marginTop="15dip"
  55. android:background="@drawable/default_cover" />
  56. </LinearLayout>
  57. </LinearLayout>
  58. <ImageView
  59. android:id="@+id/shelf_image_right"
  60. android:layout_width="wrap_content"
  61. android:layout_height="wrap_content"
  62. android:layout_alignParentRight="true"
  63. android:layout_centerVertical="true"
  64. android:background="@drawable/bookshelf_layer_right" />
  65. </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/shelf_image_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/bookshelf_layer_left" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/shelf_image_right"
android:layout_toRightOf="@+id/shelf_image_left"
android:background="@drawable/bookshelf_layer_center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" >
<Button
android:id="@+id/button_1"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip"
android:background="@drawable/default_cover" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" >
<Button
android:id="@+id/button_2"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip"
android:background="@drawable/default_cover" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal" >
<Button
android:id="@+id/button_3"
android:layout_width="80dip"
android:layout_height="110dip"
android:layout_marginTop="15dip"
android:background="@drawable/default_cover" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/shelf_image_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/bookshelf_layer_right" />
</RelativeLayout>

最后是把item绑定到listview中:

[html] view plaincopyprint?
  1. package cn.com.karl.reader;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.view.Window;
  8. import android.widget.BaseAdapter;
  9. import android.widget.ListView;
  10. public class IReaderActivity extends Activity {
  11. /** Called when the activity is first created. */
  12. private ListView shelf_list;
  13. // 书架的列数
  14. int[] size = new int[5];
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  19. setContentView(R.layout.main);
  20. shelf_list = (ListView) findViewById(R.id.shelf_list);
  21. ShelfAdapter adapter = new ShelfAdapter();
  22. shelf_list.setAdapter(adapter);
  23. }
  24. public class ShelfAdapter extends BaseAdapter {
  25. @Override
  26. public int getCount() {
  27. // TODO Auto-generated method stub
  28. return size.length;
  29. }
  30. @Override
  31. public Object getItem(int position) {
  32. // TODO Auto-generated method stub
  33. return size[position];
  34. }
  35. @Override
  36. public long getItemId(int position) {
  37. // TODO Auto-generated method stub
  38. return position;
  39. }
  40. @Override
  41. public View getView(int position, View convertView, ViewGroup parent) {
  42. // TODO Auto-generated method stub
  43. View layout = LayoutInflater.from(getApplicationContext()).inflate(
  44. R.layout.list_item, null);
  45. return layout;
  46. }
  47. }
  48. }
package cn.com.karl.reader;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.ListView;
public class IReaderActivity extends Activity {
/** Called when the activity is first created. */
private ListView shelf_list;
// 书架的列数
int[] size = new int[5];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
shelf_list = (ListView) findViewById(R.id.shelf_list);
ShelfAdapter adapter = new ShelfAdapter();
shelf_list.setAdapter(adapter);
}
public class ShelfAdapter extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return size.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return size[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View layout = LayoutInflater.from(getApplicationContext()).inflate(
R.layout.list_item, null);
return layout;
}
}
}

每一本书对应的点击事件这里并没有做,相信大家可以实现,OK,下面看一下运行后效果:

高仿iReader书架效果相关推荐

  1. vue高仿立体卡片效果(第一版)

    如图所示: 代码如下:(复制另存txt,修改.html直接运行) <!DOCTYPE html> <html> <head><meta charset=&qu ...

  2. vue高仿立体卡片效果(第二版)

    组件 如图所示: 下载地址:TAB组件 在此基础修改:vue高仿立体卡片效果(第一版) 更新记录: 1.0 修复中间分割线ios端异常,放弃border-image采用after伪元素实现

  3. vue高仿立体卡片效果(第三版)

    组件 如图所示: 使用方法 <template><div class="Home w100 h100"><!-- tab切换 start --> ...

  4. 仿ireader书架

    2019独角兽企业重金招聘Python工程师标准>>> public class ReaderActivity extends Activity {private ShelfAdap ...

  5. ireader android 源码,仿ireader书架 - androidCode的个人空间 - OSCHINA - 中文开源技术交流社区...

    public class ReaderActivity extends Activity { private ShelfAdapter mAdapter; // 书架列表 private ListVi ...

  6. Android-通过SlidingPaneLayout高仿微信6.2最新版手势滑动返回(一)

    最近更新了微信版本到6.2,发现里面有个非常好的体验,就是在第二个页面Activity能手势向右滑动返回,在手势滑动的过程中能看到第一个页面,这种体验非常赞,这里高仿了一下.这里使用的是v4包里面的S ...

  7. HTML5 Canvas 高仿逼真 3D 布料图案效果

    HTML5 规范引进了很多新特性,其中最令人期待的之一就是 Canvas 元素,HTML5 Canvas 提供了通过 JavaScript 绘制图形的方法,非常强大.下面给大家分享一个 HTML5 C ...

  8. iOS高仿微信项目、阴影圆角渐变色效果、卡片动画、波浪动画、路由框架等源码...

    2019独角兽企业重金招聘Python工程师标准>>> iOS精选源码 iOS高仿微信完整项目源码 Khala: Swift 编写的iOS/macOS 路由框架 微信左滑删除效果的实 ...

  9. 高仿阴阳师官网轮播图效果的jQuery插件

    代码地址如下: http://www.demodashi.com/demo/12302.html 插件介绍 这是一个根据阴阳师官网的轮播效果所扒下来的轮播插件,主要应用于定制个性化场景,目前源码完全公 ...

最新文章

  1. 回文数猜想代码c语言,跪求用C++写出回文数猜想程序,课程设计需要,谢谢。。。...
  2. mui汉字图标_MUI从入门到项目实战(三)增加自定义icon图标
  3. 方程的解_NOI导刊2010提高(01) 组合数
  4. ActiveMQ(07):ActiveMQ结合Spring开发--建议
  5. Catch That Cow(POJ-3278)
  6. 云小课 | 云硬盘不用了如何处理?
  7. Vivado入门创建工程之----自定义ip及其使用
  8. 孙燕姿:(Hello, I'm Stefanie...)
  9. 华为培训视频-AAA培训
  10. Selenium+JAVA淘宝登录、商品搜索、添加收货地址,提交订单、付款流程(UI)
  11. 无插件播放之http-flv
  12. phython day1
  13. mac游戏排行榜,mac好玩的游戏推荐 (一)
  14. IT程序员的抉择:我要离开帝都了
  15. DH 加密算法的使用
  16. 老照片修复的方法哪个好用?老照片修复技巧分享
  17. 基于freemarker(mht)方式导出带图片的富文本word
  18. 环己酰亚胺:一种细菌毒素的相关研究
  19. 行业案例 | 易安联零信任SDP解决方案,让企业经营更高效
  20. 百度竞价点击器_【竞价推广100问】百度竞价点击怎么收费,有计算公式吗?

热门文章

  1. 《新建文本文档》贾瑜
  2. Ubuntu 16.04 64位+Qt 5.7.1+opencv 3.2.0 + opencv_contrib 3.2.0
  3. C练题笔记之:Leetcode-654. 最大二叉树
  4. 常见行内元素、块级元素、行内块元素
  5. Win11系统.NET Framework 3.5怎么启用?
  6. Python新建、写入和修改txt(文本文档)
  7. 你了解HashMap吗?
  8. 攻防世界sherlock
  9. opencv 照片动漫风格
  10. 猫眼电影院爬虫(可用)