編輯:關於Android編程
using UnityEngine; using System.Collections; using System.Collections.Generic; public class CUIChatScrollView : UIScrollView { public delegate void OnMoveCallBack(); ////// 每次滑動結束的回調 /// public OnMoveCallBack mOnMoveCallback; public delegate void OnMoveNextPage(int pageindex); public OnMoveNextPage mOnMoveNextPage; private float mTopOffSetValue = 250; private float mBottomOffSetValue = 250; ////// 當前數據總數 /// private int mTotalCount = 0; ////// 子物體當前臨時坐標 /// private float mTempPosition = 0; ////// 子物體當前臨時相對坐標(與UIPanel偏移、DynamicComponentTran、自己本身坐標之和,如果UIpanel裁剪區域有偏移還需要加上UIPanel FinalClipRegion的偏移值(X或者Y)) /// private float mBorderValue = 0; ////// 當前顯示出來的物體列表 /// private ListmCurrentComList = new List (); /// /// 當前循環臨時加載的列表(達到臨界值需要移動的Components) /// private ListmTempComList = new List (); /// /// 掛載UIGrid的組件物體,是components父物體,UIPanel子物體 /// private Transform DynamicComponentTran; ////// 當前ScrollView依賴的UIPanel /// private UIPanel mUIPanel; ////// UIPanel最終的繪制區域、坐標 /// private Vector4 mPanelFinalClipRegion; ////// 是否需要請求下一頁數據(用於多數據分頁加載情況) /// private bool bNeedReqNextPage; ////// 每頁的數量(用於分頁) /// private int mPrePageNumber; ////// 是否是排行榜模式 /// private bool bIsRankModel; ////// 當前自己的排名 /// private int mCurrentMyRank; ////// 緩存開關 /// private DictionarybHasRequestDic = new Dictionary (); /// /// 用於比較的X坐標 /// private float xPos; ////// 用於比較的Y坐標 /// private float yPos; ////// 是否需要3D顯示效果 /// private bool bShow3DStyle = false; ////// 居中的子物體 /// public Transform mCenterTranform; ////// 子物體的depath /// private UIPanel mTempUIPanel; ////// ScrollView 的UIPanel depath。 /// private int mUIPanelDepth = 1; private int m_Index = 0; private int m_maxShowNum = 0; public void Init(List components, int maxShowNum, int totalNumber, Transform dyTransorm, Movement moveMent = Movement.Horizontal, bool needrequest = false, int prepagenum = 0, bool isrank = false, int myrank = 0, bool bshow3d = false) where T : CBaseComponent { m_Index = maxShowNum-1; m_maxShowNum = maxShowNum; mCurrentComList.Clear(); for (int i = 0, length = components.Count; i < length; i++) { if (components[i] is CBaseComponent) { mCurrentComList.Add(components[i]); } } //mCurrentComList = components as List ; DynamicComponentTran = dyTransorm; mTotalCount = totalNumber; movement = moveMent; mPanelFinalClipRegion = (mUIPanel ?? (mUIPanel = gameObject.GetComponent ())).finalClipRegion; mUIPanelDepth = mUIPanel.depth + 10;//子物體固定高出父物體深度10個單位 //if (movement == Movement.Vertical) // mOffSetValue = mPanelFinalClipRegion.w / 2 + mItemIntervalValue / 2f; //else if (moveMent == Movement.Horizontal) // mOffSetValue = mPanelFinalClipRegion.z / 2 + mItemIntervalValue / 2f; bNeedReqNextPage = needrequest; mPrePageNumber = prepagenum; bIsRankModel = isrank; mCurrentMyRank = myrank; bHasRequestDic.Clear(); bShow3DStyle = bshow3d; momentumAmount = 35f; } public override void MoveRelative(Vector3 relative) { base.MoveRelative(relative); CheckScrollView(relative); } public override void AdjustSpring(Vector3 relative) { base.AdjustSpring(relative); CheckScrollView(relative); } private void CheckScrollView(Vector3 relative) { if (mCurrentComList == null || mCurrentComList.Count == 0) return; if (movement == Movement.Horizontal) { xPos = relative.x; mCurrentComList.Sort(delegate (CBaseComponent a, CBaseComponent b) { return a.LocalPosition.x.CompareTo(b.LocalPosition.x); }); } else if (movement == Movement.Vertical) { yPos = relative.y; mCurrentComList.Sort(delegate (CBaseComponent a, CBaseComponent b) { return b.LocalPosition.y.CompareTo(a.LocalPosition.y); }); } mTempComList.Clear(); if ((yPos > 0 && movement == Movement.Vertical) || (xPos < 0 && movement == Movement.Horizontal)) { Transform temptran = mCurrentComList[mCurrentComList.Count - 1].ComTransform; if (movement == Movement.Horizontal) mTempPosition = temptran.localPosition.x; else if (movement == Movement.Vertical) mTempPosition = temptran.localPosition.y; mTempPosition = Mathf.Abs(mTempPosition); if (true) { for (int i = 0, j = mCurrentComList.Count; i < j; i++) { temptran = mCurrentComList[i].ComTransform; if (movement == Movement.Horizontal) { mBorderValue = (temptran.localPosition.x*temptran.localScale.x + transform.localPosition.x + DynamicComponentTran.localPosition.x + Mathf.Abs(mPanelFinalClipRegion.x)); if (mBorderValue > -mTopOffSetValue) { break; } } else if (movement == Movement.Vertical) { mBorderValue = (temptran.localPosition.y * temptran.localScale.y + transform.localPosition.y + DynamicComponentTran.localPosition.y + Mathf.Abs(mPanelFinalClipRegion.y)); if (mBorderValue < mTopOffSetValue) { break; } } mTempComList.Add(mCurrentComList[i]); } } for (int i = 0, j = mTempComList.Count; i < j; i++) { if (m_Index >= mTotalCount - 1) break; m_Index++; if (movement == Movement.Vertical) { float spriteHeight = NGUIMath.CalculateRelativeWidgetBounds(transform, mCurrentComList[mCurrentComList.Count - 1].ComTransform, true).size.y; mTempComList[i].LocalPosition = new Vector3(0, -(spriteHeight +mTempPosition), 0); } //mTempComList[i].LocalPosition = new Vector3(0, -(mItemIntervalValue * (i + 1) + mTempPosition), 0); mTempComList[i].InitData(m_Index); } } else if ((yPos < 0 && movement == Movement.Vertical) || (xPos > 0 && movement == Movement.Horizontal)) { Transform temptran = mCurrentComList[0].ComTransform; if (movement == Movement.Horizontal) mTempPosition = temptran.localPosition.x; else if (movement == Movement.Vertical) mTempPosition = temptran.localPosition.y; mTempPosition = Mathf.Abs(mTempPosition); if (true) { for (int i = mCurrentComList.Count - 1; i >= 0; i--) { temptran = mCurrentComList[i].ComTransform; if (movement == Movement.Horizontal) { mBorderValue = (temptran.localPosition.x + transform.localPosition.x + DynamicComponentTran.localPosition.x + Mathf.Abs(mPanelFinalClipRegion.x)); if (mBorderValue -mBottomOffSetValue) { break; } } mTempComList.Add(mCurrentComList[i]); } } for (int i = 0, j = mTempComList.Count; i < j; i++) { if (m_Index <= m_maxShowNum-1) break; m_Index--; //mTempComList[i].LocalPosition = new Vector3(0, -(mTempPosition - mItemIntervalValue * (i + 1)), 0); mTempComList[i].InitData(m_Index - m_maxShowNum+1); if (movement == Movement.Vertical) { float spriteHeight = NGUIMath.CalculateRelativeWidgetBounds(transform, mTempComList[i].ComTransform, true).size.y; Vector3 newPosition; if (i == 0) newPosition = new Vector3(0, -(mTempPosition - spriteHeight), 0); else newPosition = new Vector3(0, -(Mathf.Abs(mTempComList[i - 1].LocalPosition.y) - spriteHeight), 0); mTempComList[i].LocalPosition = newPosition; } } } if (mOnMoveCallback != null) { mOnMoveCallback(); } } }
慣例,先放效果圖,DEMO在最後 想當年博主剛接觸Android的時候,看到這個效果心中只有膜拜啊,如果慢慢的自己水平也上來了,就把當年的一個想法給圓滿了吧。好
Android DragVideo實現播放視頻時任意拖拽DragVideoA Method to Drag the Video When Playing Video一種在
1.打印日志:logt,回車:自動生成靜態Tag: private static final String TAG = "MainActivity";
國慶回了趟家,昨天真不想走,離家近的感覺太好。唉,不扯這些,說說今天的正事吧。上篇博客中介紹了自定義AutoCompleteTextView ,但是用到了一個很蹩腳的技術