- 浏览: 5818178 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
扣自goolge android.photos
用法:
/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.photos.views; import android.content.Context; import android.database.DataSetObservable; import android.database.DataSetObserver; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Filter; import android.widget.Filterable; import android.widget.FrameLayout; import android.widget.GridView; import android.widget.ListAdapter; import android.widget.WrapperListAdapter; import java.util.ArrayList; /** * A {@link GridView} that supports adding header rows in a * very similar way to {@link ListView}. * See {@link HeaderGridView#addHeaderView(View, Object, boolean)} */ public class HeaderGridView extends GridView { private static final String TAG = "HeaderGridView"; /** * A class that represents a fixed view in a list, for example a header at the top * or a footer at the bottom. */ private static class FixedViewInfo { /** The view to add to the grid */ public View view; public ViewGroup viewContainer; /** The data backing the view. This is returned from {@link ListAdapter#getItem(int)}. */ public Object data; /** <code>true</code> if the fixed view should be selectable in the grid */ public boolean isSelectable; } private ArrayList<FixedViewInfo> mHeaderViewInfos = new ArrayList<FixedViewInfo>(); private void initHeaderGridView() { super.setClipChildren(false); } public HeaderGridView(Context context) { super(context); initHeaderGridView(); } public HeaderGridView(Context context, AttributeSet attrs) { super(context, attrs); initHeaderGridView(); } public HeaderGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initHeaderGridView(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); ListAdapter adapter = getAdapter(); if (adapter != null && adapter instanceof HeaderViewGridAdapter) { ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumns()); } } @Override public void setClipChildren(boolean clipChildren) { // Ignore, since the header rows depend on not being clipped } /** * Add a fixed view to appear at the top of the grid. If addHeaderView is * called more than once, the views will appear in the order they were * added. Views added using this call can take focus if they want. * <p> * NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap * the supplied cursor with one that will also account for header views. * * @param v The view to add. * @param data Data to associate with this view * @param isSelectable whether the item is selectable */ public void addHeaderView(View v, Object data, boolean isSelectable) { ListAdapter adapter = getAdapter(); if (adapter != null && ! (adapter instanceof HeaderViewGridAdapter)) { throw new IllegalStateException( "Cannot add header view to grid -- setAdapter has already been called."); } FixedViewInfo info = new FixedViewInfo(); FrameLayout fl = new FullWidthFixedViewLayout(getContext()); fl.addView(v); info.view = v; info.viewContainer = fl; info.data = data; info.isSelectable = isSelectable; mHeaderViewInfos.add(info); // in the case of re-adding a header view, or adding one later on, // we need to notify the observer if (adapter != null) { ((HeaderViewGridAdapter) adapter).notifyDataSetChanged(); } } /** * Add a fixed view to appear at the top of the grid. If addHeaderView is * called more than once, the views will appear in the order they were * added. Views added using this call can take focus if they want. * <p> * NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap * the supplied cursor with one that will also account for header views. * * @param v The view to add. */ public void addHeaderView(View v) { addHeaderView(v, null, true); } public int getHeaderViewCount() { return mHeaderViewInfos.size(); } /** * Removes a previously-added header view. * * @param v The view to remove * @return true if the view was removed, false if the view was not a header * view */ public boolean removeHeaderView(View v) { if (mHeaderViewInfos.size() > 0) { boolean result = false; ListAdapter adapter = getAdapter(); if (adapter != null && ((HeaderViewGridAdapter) adapter).removeHeader(v)) { result = true; } removeFixedViewInfo(v, mHeaderViewInfos); return result; } return false; } private void removeFixedViewInfo(View v, ArrayList<FixedViewInfo> where) { int len = where.size(); for (int i = 0; i < len; ++i) { FixedViewInfo info = where.get(i); if (info.view == v) { where.remove(i); break; } } } @Override public void setAdapter(ListAdapter adapter) { if (mHeaderViewInfos.size() > 0) { HeaderViewGridAdapter hadapter = new HeaderViewGridAdapter(mHeaderViewInfos, adapter); int numColumns = getNumColumns(); if (numColumns > 1) { hadapter.setNumColumns(numColumns); } super.setAdapter(hadapter); } else { super.setAdapter(adapter); } } private class FullWidthFixedViewLayout extends FrameLayout { public FullWidthFixedViewLayout(Context context) { super(context); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int targetWidth = HeaderGridView.this.getMeasuredWidth() - HeaderGridView.this.getPaddingLeft() - HeaderGridView.this.getPaddingRight(); widthMeasureSpec = MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.getMode(widthMeasureSpec)); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } /** * ListAdapter used when a HeaderGridView has header views. This ListAdapter * wraps another one and also keeps track of the header views and their * associated data objects. *<p>This is intended as a base class; you will probably not need to * use this class directly in your own code. */ private static class HeaderViewGridAdapter implements WrapperListAdapter, Filterable { // This is used to notify the container of updates relating to number of columns // or headers changing, which changes the number of placeholders needed private final DataSetObservable mDataSetObservable = new DataSetObservable(); private final ListAdapter mAdapter; private int mNumColumns = 1; // This ArrayList is assumed to NOT be null. ArrayList<FixedViewInfo> mHeaderViewInfos; boolean mAreAllFixedViewsSelectable; private final boolean mIsFilterable; public HeaderViewGridAdapter(ArrayList<FixedViewInfo> headerViewInfos, ListAdapter adapter) { mAdapter = adapter; mIsFilterable = adapter instanceof Filterable; if (headerViewInfos == null) { throw new IllegalArgumentException("headerViewInfos cannot be null"); } mHeaderViewInfos = headerViewInfos; mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos); } public int getHeadersCount() { return mHeaderViewInfos.size(); } @Override public boolean isEmpty() { return (mAdapter == null || mAdapter.isEmpty()) && getHeadersCount() == 0; } public void setNumColumns(int numColumns) { if (numColumns < 1) { throw new IllegalArgumentException("Number of columns must be 1 or more"); } if (mNumColumns != numColumns) { mNumColumns = numColumns; notifyDataSetChanged(); } } private boolean areAllListInfosSelectable(ArrayList<FixedViewInfo> infos) { if (infos != null) { for (FixedViewInfo info : infos) { if (!info.isSelectable) { return false; } } } return true; } public boolean removeHeader(View v) { for (int i = 0; i < mHeaderViewInfos.size(); i++) { FixedViewInfo info = mHeaderViewInfos.get(i); if (info.view == v) { mHeaderViewInfos.remove(i); mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos); mDataSetObservable.notifyChanged(); return true; } } return false; } @Override public int getCount() { if (mAdapter != null) { return getHeadersCount() * mNumColumns + mAdapter.getCount(); } else { return getHeadersCount() * mNumColumns; } } @Override public boolean areAllItemsEnabled() { if (mAdapter != null) { return mAreAllFixedViewsSelectable && mAdapter.areAllItemsEnabled(); } else { return true; } } @Override public boolean isEnabled(int position) { // Header (negative positions will throw an ArrayIndexOutOfBoundsException) int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (position < numHeadersAndPlaceholders) { return (position % mNumColumns == 0) && mHeaderViewInfos.get(position / mNumColumns).isSelectable; } // Adapter final int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = 0; if (mAdapter != null) { adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.isEnabled(adjPosition); } } throw new ArrayIndexOutOfBoundsException(position); } @Override public Object getItem(int position) { // Header (negative positions will throw an ArrayIndexOutOfBoundsException) int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (position < numHeadersAndPlaceholders) { if (position % mNumColumns == 0) { return mHeaderViewInfos.get(position / mNumColumns).data; } return null; } // Adapter final int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = 0; if (mAdapter != null) { adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getItem(adjPosition); } } throw new ArrayIndexOutOfBoundsException(position); } @Override public long getItemId(int position) { int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (mAdapter != null && position >= numHeadersAndPlaceholders) { int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getItemId(adjPosition); } } return -1; } @Override public boolean hasStableIds() { if (mAdapter != null) { return mAdapter.hasStableIds(); } return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { // Header (negative positions will throw an ArrayIndexOutOfBoundsException) int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns ; if (position < numHeadersAndPlaceholders) { View headerViewContainer = mHeaderViewInfos .get(position / mNumColumns).viewContainer; if (position % mNumColumns == 0) { return headerViewContainer; } else { if (convertView == null) { convertView = new View(parent.getContext()); } // We need to do this because GridView uses the height of the last item // in a row to determine the height for the entire row. convertView.setVisibility(View.INVISIBLE); convertView.setMinimumHeight(headerViewContainer.getHeight()); return convertView; } } // Adapter final int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = 0; if (mAdapter != null) { adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getView(adjPosition, convertView, parent); } } throw new ArrayIndexOutOfBoundsException(position); } @Override public int getItemViewType(int position) { int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) { // Placeholders get the last view type number return mAdapter != null ? mAdapter.getViewTypeCount() : 1; } if (mAdapter != null && position >= numHeadersAndPlaceholders) { int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getItemViewType(adjPosition); } } return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER; } @Override public int getViewTypeCount() { if (mAdapter != null) { return mAdapter.getViewTypeCount() + 1; } return 2; } @Override public void registerDataSetObserver(DataSetObserver observer) { mDataSetObservable.registerObserver(observer); if (mAdapter != null) { mAdapter.registerDataSetObserver(observer); } } @Override public void unregisterDataSetObserver(DataSetObserver observer) { mDataSetObservable.unregisterObserver(observer); if (mAdapter != null) { mAdapter.unregisterDataSetObserver(observer); } } @Override public Filter getFilter() { if (mIsFilterable) { return ((Filterable) mAdapter).getFilter(); } return null; } @Override public ListAdapter getWrappedAdapter() { return mAdapter; } public void notifyDataSetChanged() { mDataSetObservable.notifyChanged(); } } }
用法:
mHeaderView = LayoutInflater.from(getActivity()) .inflate(R.layout.album_header, getGridView(), false); ((HeaderGridView) getGridView()).addHeaderView(mHeaderView, null, false);
发表评论
-
NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端
2018-10-31 20:45 6987网上有一个StickyScrollView,称之为粘性Scro ... -
自定义Behavior实现AppBarLayout越界弹性效果
2017-03-31 09:33 10364一、继承AppBarLayout.Beha ... -
Android - 一种相似图片搜索算法的实现
2017-03-31 09:33 2621算法 缩小尺寸。 将图片缩小到8x8的尺寸,总共64个 ... -
使用SpringAnimation实现带下拉弹簧动画的 ScrollView
2017-03-30 11:30 2847在刚推出的 Support Library 25.3.0 里面 ... -
Android为应用添加角标(Badge)
2017-03-30 11:21 61741.需求简介 角标是什么意思呢? 看下图即可明了: 可 ... -
Android端与笔记本利用局域网进行FTP通信
2017-03-23 10:17 977先看图 打开前: 打开后: Activity类 ... -
PorterDuffColorFilter 在项目中的基本使用
2017-03-03 10:58 1353有时候标题栏会浮在内容之上,而内容会有颜色的变化,这时候就要求 ... -
ColorAnimationView 实现了滑动Viewpager 时背景色动态变化的过渡效果
2017-02-24 09:41 2220用法在注释中: import android.anima ... -
迷你轻量级全方向完美滑动处理侧滑控件SlideLayout
2017-01-16 16:53 2594纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 sup ... -
Effect
2017-01-05 09:57 0https://github.com/JetradarMobi ... -
动态主题库Colorful,容易地改变App的配色方案
2016-12-27 14:49 2563Colorful是一个动态主题库,允许您很容易地改变App的配 ... -
对视图的对角线切割DiagonalView
2016-12-27 14:23 1116提供对视图的对角线切割,具有很好的用户定制 基本用法 ... -
仿淘宝京东拖拽商品详情页上下滚动黏滞效果
2016-12-26 16:53 3490比较常用的效果,有现成的,如此甚好!:) import ... -
让任意view具有滑动效果的SlideUp
2016-12-26 09:26 1705基本的类,只有一个: import android.a ... -
AdvancedWebView
2016-12-21 09:44 16https://github.com/delight-im/A ... -
可设置圆角背景边框的按钮, 通过调节色彩明度自动计算按下(pressed)状态颜色
2016-11-02 22:13 1920可设置圆角背景边框的的按钮, 通过调节色彩明度自动计算按下(p ... -
网络请求库相关
2016-10-09 09:35 62https://github.com/amitshekhari ... -
ASimpleCache一个简单的缓存框架
2015-10-26 22:53 2177ASimpleCache 是一个为android制定的 轻量级 ... -
使用ViewDragHelper实现的DragLayout开门效果
2015-10-23 10:55 3414先看一下图,有个直观的了解,向下拖动handle就“开门了”: ... -
保证图片长宽比的同时拉伸图片ImageView
2015-10-16 15:40 3732按比例放大图片,不拉伸失真 import android. ...
相关推荐
Android中实现带有头部的GridView(HeaderGridView),具体介绍,见我的博客:http://blog.csdn.net/ch1451082329/article/details/46801497
我们都知道ListView有addHeaderView和addFooterView两个方法。其中addHeaderView是添加头部...public class HeaderGridView extends GridView { private static final String TAG = HeaderGridView; /** * A class
在GridView中添加Header,可以增强用户体验,使得用户更清晰地理解数据的分类或结构。Header通常包含列名或者功能说明,是数据展示的重要组成部分。接下来,我们将详细探讨如何在GridView中添加Header以及相关的...
本教程将详细介绍如何使用RecyclerView来实现一个带有Header和Footer的效果,类似于GridView的功能。 首先,理解RecyclerView的基本架构是至关重要的。RecyclerView由Adapter、LayoutManager和ViewHolder三部分组成...
有图有介绍:请参考我的博客http://blog.csdn.net/panjidong_3/article/details/16985107 可以实现头部带有固定导航条和有索引导航功能的gridview,使用方便。
在这个名为“带有GridView的Combox控件.rar”的压缩包中,我们可以推测它包含了一个使用C#编写的Windows Forms应用示例,其中可能着重展示了如何将GridView和ComboBox控件结合使用。GridView通常用于显示数据网格,...
在Android开发中,GridView是一个非常常用的控件,它允许我们以网格的形式展示数据。然而,系统默认的GridView并不总是能满足所有需求,特别是当涉及到个性化设计时,如自定义表头。本篇将深入探讨如何根据实际应用...
在QML(Qt Quick)中,GridView是一种布局管理器,用于在二维网格中显示元素,通常用于创建诸如图片库、应用列表等用户界面。而在这个主题中,我们要讨论如何在GridView中添加滚动条和翻页功能,使得用户可以通过...
在ASP.NET开发中,GridView控件是用于展示数据的强大工具,尤其在呈现表格形式的数据时。在本项目中,我们探讨的主题是“GridView内嵌套使用GridView”,这通常是为了实现更复杂的数据显示,例如,当数据有层次关系...
标题和描述所提及的问题正是针对这一情况,提供了一个解决方案,即在UpdatePanel更新过程中保持GridView的Header固定并保持用户的滚动位置。 首先,我们需要理解GridView的工作原理。GridView会根据数据源自动创建...
在标题“gridview嵌套gridview案例说明”中,我们关注的核心点是GridView控件的嵌套使用,即将一个GridView控件放置在另一个GridView控件内部,以构建一个多级数据展示的结构。这种技术通常用于展示层次结构数据,...
mycustomField.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, "删除"); mycustomField.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "", lb); // 将新创建的列添加到...
在IT领域,尤其是在Web开发中,GridView控件是ASP.NET中一个非常强大的工具,用于在网页上展示数据。本文将详细介绍如何在C#与ASP.NET环境下设置GridView的列宽,这是一个常见但至关重要的操作,能够显著提升用户...
在ASP.NET开发中,GridView控件是用于展示数据表格的常用工具,尤其在处理大量数据时,它提供了灵活的配置和样式化选项。本实例主要关注如何实现GridView的固定表头和列,使得用户在滚动浏览长表格时,表头和部分列...
自定义带分隔线的GridView,详见本人博客《为GridView添加分割线》
在Android开发中,GridView是一种非常常见的布局控件,它允许我们以网格的形式展示数据,通常用于创建像照片墙、应用列表等界面。本教程将深入探讨如何自定义各种风格的GridView,包括刷新、加载和横向展示等特性。 ...
gridview自带分页源码,及数据分析;gridview自带分页源码,及数据分析;gridview自带分页源码,及数据分析;
然而,当我们需要实现一个横向滑动的单行GridView,并带有左右按钮来切换显示的内容时,就需要对默认的GridView进行一些定制和调整。 首先,为了实现横向滑动,我们需要改变GridView的布局参数。默认情况下,...
在Android开发中,GridView是一种常见的布局管理器,用于展示一系列数据项,通常以网格形式排列。在许多应用中,为了提供更好的用户体验,我们可能需要实现GridView的动态交互功能,如拖拽排序。本教程将详细介绍...
例如,增加一个HeaderView,并在滚动时监听ScrollView的滚动事件,根据滚动位置调整Header的可见性。 五、Adapter的优化 为了保证性能,Adapter需要优化数据加载和视图复用。使用convertView复用机制,避免每次滚动...