短視訊平臺原始碼,動態上傳的圖片以九宮格形式展示
短視訊平臺原始碼,動態上傳的圖片以九宮格形式展示實現的相關程式碼
public abstract class NineGridAdapter { protected Context context; protected List list; public NineGridAdapter(Context context, List list) { this.context = context; this.list = list; } public abstract int getCount(); public abstract String getUrl(int positopn); public abstract Object getItem(int position); public abstract long getItemId(int position); public abstract View getView(int i, View view); }
自定義View多圖控制元件
public class NineGridlayout extends ViewGroup { private NineGridAdapter adapter; private OnItemClickListerner onItemClickListerner; // 行間距 private int lineSpace; //列間距 private int gap; private final int DEFAULT_WIDTH = 140; private int columns;// private int rows;// private int totalWidth; private Context context; int singleWidth = 0, singleHeight = 0; private int defaultWidth, defaultHeight; private int oldCount; public NineGridlayout(Context context) { this(context, null); } public NineGridlayout(Context context, AttributeSet attrs) { this(context, attrs, 0); } public NineGridlayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.context = context; gap = dip2px(context, 10); lineSpace = dip2px(context,10); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); defaultWidth = defaultHeight = dip2px(context, DEFAULT_WIDTH); } public void setDefaultWidth(int defaultWidth) { this.defaultWidth = defaultWidth; } public void setDefaultHeight(int defaultHeight) { this.defaultHeight = defaultHeight; } public void setAdapter(NineGridAdapter adapter) { this.adapter = adapter; if (adapter == null) { return; } //初始化佈局形狀 generateChildrenLayout(adapter.getCount()); //這裡做一個重用view的處理 // if (oldCount == 0) { removeAllViews(); for (int i = 0; i < adapter.getCount(); i++) { View itemView = adapter.getView(i, null); addView(itemView, generateDefaultLayoutParams()); } // } /*else { //以前新增過view int newViewCount = adapter.getCount(); if (oldCount > newViewCount) { removeViews(newViewCount - 1, oldCount - newViewCount); for (int i = 0; i < newViewCount - 1; i++) { adapter.getView(i, getChildAt(i)); } } else if (oldCount < newViewCount) { for (int i = 0; i < newViewCount - oldCount; i++) { View itemView = adapter.getView(i, null); addView(itemView, generateDefaultLayoutParams()); } } }*/ oldCount = adapter.getCount(); requestLayout(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int sizeWidth = MeasureSpec.getSize(widthMeasureSpec); int sizeHeight = MeasureSpec.getSize(heightMeasureSpec); totalWidth = sizeWidth - getPaddingLeft() - getPaddingRight(); if (adapter != null && adapter.getCount() > 0) { int measureWidth, measureHeight; int childrenCount = adapter.getCount(); if (childrenCount == 1) { singleWidth = defaultWidth; singleHeight = defaultHeight; } else { singleWidth = (totalWidth - gap * (3 - 1)) / 3; singleHeight = singleWidth; } measureChildren(MeasureSpec.makeMeasureSpec(singleWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(singleHeight, MeasureSpec.EXACTLY)); measureWidth = singleWidth * columns + gap * (columns - 1); measureHeight = singleHeight * rows + lineSpace * (rows - 1); setMeasuredDimension(sizeWidth, measureHeight); } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { layoutChildrenView(); } private void layoutChildrenView() { if (adapter == null || adapter.getCount() == 0) { return; } int childrenCount = adapter.getCount(); for (int i = 0; i < childrenCount; i++) { int[] position = findPosition(i); int left = (singleWidth + gap) * position[1] + getPaddingLeft(); int top = (singleHeight + lineSpace) * position[0] + getPaddingTop(); int right = left + singleWidth; int bottom = top + singleHeight; ImageView childrenView = (ImageView) getChildAt(i); if (childrenCount == 1) { //只有一張圖片 childrenView.setScaleType(ImageView.ScaleType.FIT_CENTER); } else { childrenView.setScaleType(ImageView.ScaleType.CENTER_CROP); } final int itemPosition = i; childrenView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (onItemClickListerner != null) { onItemClickListerner.onItemClick(v, itemPosition); } } }); childrenView.layout(left, top, right, bottom); } } private int[] findPosition(int childNum) { int[] position = new int[2]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if ((i * columns + j) == childNum) { position[0] = i;//行 position[1] = j;//列 break; } } } return position; } public int getGap() { return gap; } public void setGap(int gap) { this.gap = gap; } /** * 根據圖片個數確定行列數量 * 對應關係如下 * numrowcolumn * 1 11 * 2 12 * 3 13 * 4 22 * 5 23 * 6 23 * 7 33 * 8 33 * 9 33 * * @param length */ private void generateChildrenLayout(int length) { if (length <= 3) { rows = 1; columns = length; } else if (length <= 6) { rows = 2; columns = 3; if (length == 4) { columns = 2; } } else { rows = 3; columns = 3; } } /** * dp to px */ public static int dip2px(Context context, double dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } public void setOnItemClickListerner(OnItemClickListerner onItemClickListerner) { this.onItemClickListerner = onItemClickListerner; } public interface OnItemClickListerner { public void onItemClick(View view, int position); } }
以上就是短視訊平臺原始碼,動態上傳的圖片以九宮格形式展示實現的相關程式碼, 更多內容歡迎關注之後的文章
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2838327/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 短視訊直播原始碼,動態釋出時選擇圖片、上傳圖片原始碼
- 短視訊平臺原始碼,自定義上傳有邊框的背景圖片原始碼
- 短視訊平臺原始碼,登入介面插入背景圖片原始碼
- 短視訊直播原始碼,自動對上傳的圖片進行識別原始碼
- 短視訊平臺開發,在上傳圖片時,自動新增平臺的水印
- 短視訊平臺開發,圖片上傳和圖片預覽功能實現
- 關於短視訊平臺原始碼動態廣場自動播放gif動圖原始碼
- 短視訊系統原始碼,上傳圖片自適應拉伸符合高度原始碼
- 短視訊app開發,短視訊動態功能上傳圖片時,規定圖片壓縮的大小APP
- python九宮格圖片的原理Python
- 【微信小程式雲開發】1分鐘學會實現上傳、下載、預覽、刪除圖片,並且以九宮格展示圖片微信小程式
- 短視訊平臺原始碼,IOS圖文混排基礎原始碼iOS
- 短視訊app原始碼,提示以按鈕彈窗的形式實現APP原始碼
- 短視訊原始碼,視訊轉為圖片儲存原始碼
- 短視訊平臺搭建,生成圖片形狀的位置
- 短視訊原始碼,python使用post提交圖片原始碼Python
- 短視訊平臺原始碼,介面支援上下、左右的任意滑動原始碼
- 短視訊平臺搭建,圖片進行預覽上傳、刪除,讀取本地檔案
- uniapp uview 上傳圖片,資料以formData + File 形式傳輸APPViewORM
- 短視訊平臺搭建,實現banner自動滑動展示效果
- 短視訊平臺開發,將圖片、視訊儲存到本地的相簿中
- 短視訊直播原始碼,自定義圖片或視訊的迴圈播放原始碼
- 短視訊平臺原始碼,透明導航欄 AppBar原始碼APP
- 直播商城原始碼,商品展示分為視訊和圖片展示兩種方式原始碼
- 直播平臺原始碼,視訊抽幀作為圖片儲存原始碼
- 短視訊app原始碼,點選檢視圖片,雙指放大APP原始碼
- 短視訊平臺原始碼,Android 左右滑動顯示和隱藏原始碼Android
- 短視訊直播原始碼,拖動滑塊實現圖片驗證效果原始碼
- 短視訊app開發,三種圖片並排展示的方式APP
- 短視訊平臺原始碼,自定義流式佈局--kotlin原始碼Kotlin
- 短視訊帶貨原始碼,儲存圖片到相簿/相簿原始碼
- Python 帶你一鍵生成朋友圈超火的九宮格短視訊Python
- 直播平臺原始碼,上傳本地圖片實現個人名片背景圖輪播原始碼地圖
- 短視訊平臺原始碼,首頁視訊之間設定間距原始碼
- 短視訊平臺原始碼,平臺顯示時間,時間格式的轉換原始碼
- 短視訊系統原始碼,平臺的時間處理方式原始碼
- 遞迴、迭代和動態規劃:以九宮格鍵盤為例遞迴動態規劃
- 全平臺短視訊無水印解析原始碼(支援超30多個平臺)原始碼