android使用gridview的书架效果,需要使用自定义的gridview来填充每行的背景,核心代码如下:

BookGridView.java

/*** 书架效果**/
public class BookGridView extends GridView {private Bitmap background;Context context;public BookGridView(Context context, AttributeSet attrs) {super(context, attrs);this.context = context;background = null;}@Overrideprotected void dispatchDraw(Canvas canvas) {int count = getChildCount();int top = count > 0 ? getChildAt(0).getTop() : 0;int width = getWidth();int height = getHeight();int totalCount = this.getCount();//如果总数为0自然没必要计算高度并画图if (totalCount > 0) {//获取列数int numColumns=3;// 计算行高,通过行数和控件高度计算int rowCount = totalCount / numColumns;if (totalCount % numColumns != 0) {rowCount++;}int rowHeight = height / rowCount;if (background == null) {background = BitmapFactory.decodeResource(getResources(),R.drawable.bookshelf_layer_center);background = Bitmap.createScaledBitmap(background, width,rowHeight, true);}int backgroundWidth = background.getWidth();int backgroundHeight = background.getHeight();for (int y = top; y < height; y += backgroundHeight) {for (int x = 0; x < width; x += backgroundWidth) {canvas.drawBitmap(background, x, y, null);}}}super.dispatchDraw(canvas);}}

使用如下:

            <com.my.views.BookGridViewandroid:id="@+id/gridview_custom"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:background="@color/transparent"android:cacheColorHint="@color/transparent"android:columnWidth="100dip"android:gravity="center_vertical"android:horizontalSpacing="0dip"android:listSelector="@color/transparent"android:numColumns="3"android:paddingBottom="0dp"android:scrollbars="none"android:stretchMode="spacingWidthUniform"android:verticalSpacing="0dip" />

具体可以参照:

http://blog.csdn.net/caizhegnhao/article/details/38857531 ,附件给出它的下载源码

android使用gridview的书架效果相关推荐

  1. android书架效果 .

    以前也模仿者ireader实现了书架的效果,但是那种是使用listview实现的,并不好用.绝大多数都是用gridview实现的,网上这方面资料比较少,有些开源的电子书都是重点做了阅读,并没有像ire ...

  2. android书架效果

    以前也模仿者ireader实现了书架的效果,但是那种是使用listview实现的,并不好用.绝大多数都是用gridview实现的,网上这方面资料比较少,有些开源的电子书都是重点做了阅读,并没有像ire ...

  3. android gridview item 边框,Android实现为GridView添加边框效果

    为GridView添加边框效果,供大家参考,具体内容如下 1.自定义GridView的item样式: grid_item.xml文件 android:layout_width="wrap_c ...

  4. android gridview行分割线,Android使用GridView实现表格分割线效果

    使用gridview实现表格分割线效果,网格布局表格布局也是可以实现的. 效果如下: 1.主函数代码: package com.example.qd.douyinwu; import android. ...

  5. android 使用GridView实现Gallery的效果,并且从最左边开始

    1.首先设计man.xml这里使用HorizontalScrollView结合GridView实现Gallery的左右滚动效果,并且解决了Gallery从中间开始的问题,GridView可以从最左边开 ...

  6. Android实现GridView的item长按拖动删除完美实现(带动画效果)

    领导这几天让做一个项目,就是可以实现像支付宝首页一样的可以长按拖动,删除的界面,以前没做过,领导让我做的时候觉得简直是老虎吃天,无从下手啊,可是领导的任务还是要实现的,没办法,就自己网上找咯,但是网上 ...

  7. Android中GridView的实现实例

    实现效果: activity文件代码: package com.tmacsky; import android.app.Activity; import android.os.Bundle; impo ...

  8. 50个Android开发人员必备UI效果源码[转载]

    Android 仿微信之主页面实现篇 Android 仿微信之界面导航篇 Android 高仿QQ 好友分组列表 Android 高仿QQ 界面滑动效果 Android 高仿QQ 登陆界面 Andro ...

  9. android 书架菜单,Android入门3--做一个书架

    修改名称 创建项目的时候,APP的名字取为英文或者拼音,是为了简便,但是显示在界面上,我们当然希望它是中文的. taoguanstring> 我们要做的很简单,就是在string.xml中,将a ...

最新文章

  1. 企业级Nginx服务基础到架构优化详解--25条
  2. 【AGC+FPGA】基于FPGA的数字AGC自适应增益设计,应用在BPSK调制解调系统中
  3. 奇异值分解SVD应用——LSI
  4. 技术人员转型是件痛苦的事情~
  5. POJ 1442 Black Box(大小堆,求第K小的元素)
  6. 3+1保障:高可用系统稳定性是如何炼成的?
  7. C语言 extern “C” - C语言零基础入门教程
  8. mysql left 数学原理,MySQL全面瓦解21(番外):一次深夜优化亿级数据分页的奇妙经历...
  9. python语言的核心理念是_Python 编程语言的核心是什么?
  10. 信息学奥赛一本通(1128:图像模糊处理)
  11. 续php的一些基本概念
  12. 目标跟踪学习笔记_2(particle filter初探1)
  13. 注塑机服务器显示e011,海天注塑机伺服控制器故障代码表.doc
  14. Docker下载redis镜像
  15. 拼音表大全图_【居家乐学】让拼音活起来
  16. PDM的工程图纸管理解决方案
  17. 单片机七阶音符_单片机教程二十七:单片机音乐程序设计(含源程序)
  18. 深度学习——AI领域会议列表(以备准备和更新论文存储使用)
  19. uni-app云打包 No enum constant com.pandora.pack.core.PackagePlatform.ANDROID_CLC
  20. iis6.0 index.php,IIS6.0下Wordpress 去掉 index.php 和 category 的方法小结

热门文章

  1. MySQL 查询七天每天的数据总数
  2. 数据流程图与数据字典
  3. 鸿蒙操作系统系列——Hi3516 OpenHarmony_2.0_canary版本设备开发起始篇
  4. 最简单的正交试验教程,一次搞懂它!
  5. 基于微信小程序的二手交易平台系统
  6. [附源码]Nodejs计算机毕业设计江西婺源旅游文化推广系统Express(程序+LW)
  7. 90后用 HTTP 写了一篇恋爱日记
  8. 如何进行App性能测试?iTest工具助力你轻松实现!
  9. “unix:///tmp/supervisor.sock no such file“ 错误解决方案
  10. 二本浙大计算机考研,二本考研逆袭浙大:宝贵经历送给即将上路的你!