Java Code Examples for android.widget.GridView#getNumColumns()
The following examples show how to use
android.widget.GridView#getNumColumns() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridViewHelpsAdapter.java From styT with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { convertView = inflater.inflate(R.layout.lxw_item_helps_gridview, null); holder = new ViewHolder(); holder.imageView = (ImageView) convertView.findViewById(R.id.lxw_id_item_helps_gridview_img); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } GridView gridView = (GridView) parent; int horizontalSpacing = gridView.getHorizontalSpacing(); int numCloms = gridView.getNumColumns(); int itemWidth = (gridView.getWidth() - (numCloms * horizontalSpacing) - gridView.getPaddingLeft() - gridView.getPaddingRight()) / numCloms; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(itemWidth, itemWidth); holder.imageView.setLayoutParams(lp); holder.imageView.setImageResource(R.drawable.pictures_no); String path = mDatas.get(position).getUrl(); // ImageLoader.getInstance(3, ImageLoader.Type.LIFO).loaderImage(path,holder.imageView,true); Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView); return convertView; }
Example 2
Source File: ScrollSpeedListener.java From odyssey with GNU General Public License v3.0 | 5 votes |
/** * Callback method to be invoked when the list or grid has been scrolled. */ @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { // New row started if this is true. if (firstVisibleItem != mLastFirstVisibleItem) { long currentTime = System.currentTimeMillis(); if (currentTime == mLastTime) { return; } // Calculate the duration of scroll per line long timeScrollPerRow = currentTime - mLastTime; if (view instanceof GridView) { GridView gw = (GridView) view; mScrollSpeed = (int) (1000 / timeScrollPerRow) * gw.getNumColumns(); } else { mScrollSpeed = (int) (1000 / timeScrollPerRow); } // Calculate how many items per second of loading images is possible int possibleItems = (int) (1000 / mAdapter.getAverageImageLoadTime()); // Set the scrollspeed in the adapter mAdapter.setScrollSpeed(mScrollSpeed); // Save values for next comparsion mLastFirstVisibleItem = firstVisibleItem; mLastTime = currentTime; // Start the grid image loader task only if scroll speed is slow enough: // The devices is able to render the images needed for the scroll speed if (mScrollSpeed < possibleItems) { for (int i = 0; i < visibleItemCount; i++) { GenericImageViewItem item = (GenericImageViewItem) view.getChildAt(i); item.startCoverImageTask(); } } } }
Example 3
Source File: ListAdapter.java From Android-ImageManager with MIT License | 5 votes |
@SuppressLint("NewApi") private int getImageHeight(final GridView gridView) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) return (int)(gridView.getColumnWidth() * IMAGE_SIZE_RATIO); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) return (int)((getScreenWidth() / gridView.getNumColumns()) * IMAGE_SIZE_RATIO); return imgHeight; }
Example 4
Source File: ListViewUtils.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 计算 GridView 高度 * @param gridView {@link GridView} * @param setParams 是否 setLayoutParams * @return GridView 高度 */ public static int calcGridViewHeight(final GridView gridView, final boolean setParams) { if (gridView == null) return 0; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return 0; try { // Adapter ListAdapter listAdapter = gridView.getAdapter(); // Item 总条数 int itemCount = listAdapter.getCount(); // 没数据则直接跳过 if (itemCount == 0) return 0; // 高度 int height = 0; // 获取一共多少列 int numColumns = gridView.getNumColumns(); // 每列之间的间隔 | int horizontalSpacing = gridView.getHorizontalSpacing(); // 每行之间的间隔 - int verticalSpacing = gridView.getVerticalSpacing(); // 获取倍数 ( 行数 ) int lineNumber = NumberUtils.getMultiple(itemCount, numColumns); // 计算总共的宽度 - (GridView 宽度 - 列分割间距 ) / numColumns int childWidth = (gridView.getWidth() - (numColumns - 1) * horizontalSpacing) / numColumns; // 记录每行最大高度 int[] rowHeightArrays = new int[lineNumber]; // 临时高度 - 保存行中最高的列高度 int tempHeight; // 循环每一行绘制每个 Item 并保存 Bitmap for (int i = 0; i < lineNumber; i++) { // 清空高度 tempHeight = 0; // 循环列数 for (int j = 0; j < numColumns; j++) { // 获取对应的索引 int position = i * numColumns + j; // 如果大于总数据则跳过 if (position < itemCount) { View childView = listAdapter.getView(position, null, gridView); WidgetUtils.measureView(childView, childWidth); int itemHeight = childView.getMeasuredHeight(); // 保留最大高度 tempHeight = Math.max(itemHeight, tempHeight); } // 记录高度并累加 if (j == numColumns - 1) { height += tempHeight; rowHeightArrays[i] = tempHeight; } } } // 追加子项间分隔符占用的高度 height += (verticalSpacing * (lineNumber - 1)); // 是否需要设置高度 if (setParams) { ViewGroup.LayoutParams params = gridView.getLayoutParams(); params.height = height; gridView.setLayoutParams(params); } return height; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "calcGridViewHeight"); } return 0; }
Example 5
Source File: YouTubeCursorAdapter.java From UTubeTV with The Unlicense | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { GridView gridView = (GridView) parent; boolean multiColumns = gridView.getNumColumns() > 1; convertView = prepareViews(convertView, parent, multiColumns); ViewHolder holder = (ViewHolder) convertView.getTag(); Cursor cursor = (Cursor) getItem(position); YouTubeData itemMap = mRequest.databaseTable().cursorToItem(cursor, mReusedData); Picasso.with(mContext).load(itemMap.mThumbnail) .fit() // .noFade() // .resize(250, 250) // put into dimens for dp values .into(holder.image); boolean hidden = itemMap.isHidden(); holder.image.setDrawHiddenIndicator(hidden); holder.title.setText(itemMap.mTitle); // hide description if empty if (holder.description != null) { String desc = itemMap.mDescription; if (desc != null && (desc.length() > 0)) { holder.description.setVisibility(View.VISIBLE); holder.description.setText(desc); } else { if (multiColumns) { holder.description.setVisibility(View.VISIBLE); holder.description.setText(" "); // min lines doesn't work with "", used a space } else holder.description.setVisibility(View.GONE); } } // set video id on menu button so clicking can know what video to act on if (mTheme.mSupportsMenuButton && (itemMap.mVideo != null || itemMap.mPlaylist != null)) { holder.menuButton.setVisibility(View.VISIBLE); holder.menuButton.setListener(this); holder.menuButton.mId = itemMap.mID; } else { holder.menuButton.setVisibility(View.GONE); } String duration = itemMap.mDuration; if (duration != null) { holder.duration.setText(duration); } else { long count = itemMap.mItemCount; holder.duration.setText(Long.toString(count) + (count == 1 ? " video" : " videos")); } // card number holder.cardNumber.setText(Long.toString(position+1)); Spannable date = mDateCache.spannable(itemMap.mPublishedDate); if (date != null) { holder.pubDate.setText(date); } else { holder.pubDate.setText(""); } return convertView; }