- 浏览: 271593 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
flyingsnowff:
支付宝官方在线文档中心:https://doc.open.al ...
如何集成支付宝官方文档 -
timer_yin:
果然是这样
[转帖] 安装Eclipse插件长时间卡在 calculating requirements and dependencies -
dai_lm:
lyx0224 写道强~~~~~过奖,只是总结了前人的智慧,拼 ...
通过Wifi实现设备间的通信 -
lyx0224:
强~~~~~
通过Wifi实现设备间的通信 -
Goro:
帅!
自己封装的支持自动对焦的CameraView
在Android上模拟WP7的MetroUI
MetroItem
MetroView
MetroItem
import android.view.View; public class MetroItem { private View mMetroView = null; private int mRow = 0; private int mRowSpan = 1; private int mCol = 0; private int mColSpan = 1; /** * @param v * @param row * @param col */ public MetroItem(View v, int row, int col) { this(v, row, 1, col, 1); } /** * @param v * @param row * @param rowspan * @param col * @param colspan */ public MetroItem(View v, int row, int rowspan, int col, int colspan) { mMetroView = v; if (row < 0) throw new IllegalArgumentException("row < 0"); mRow = row; if (col < 0) throw new IllegalArgumentException("col < 0"); mCol = col; if (rowspan < 1) throw new IllegalArgumentException("rowspan < 1"); mRowSpan = rowspan; if (colspan < 1) throw new IllegalArgumentException("colspan < 1"); mColSpan = colspan; } public View getMetroView() { return mMetroView; } public int getRow() { return mRow; } public int getRowSpan() { return mRowSpan; } public int getCol() { return mCol; } public int getColSpan() { return mColSpan; } }
MetroView
import java.util.ArrayList; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.Scroller; import com.test.android.metro.R; import com.test.android.metro.model.MetroItem; public class MetroView extends ViewGroup { public static enum OrientationType { All, Vertical, Horizontal }; private static final String TAG = "MetroView"; private static final LayoutParams FILL_FILL = new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); /** Default count of visible items */ private static final int DEF_VISIBLE_ROWS = 5; private static final int DEF_VISIBLE_COLS = 2; private OrientationType mOrientation = OrientationType.Horizontal; // Count of visible items protected int visibleRows = DEF_VISIBLE_ROWS; protected int visibleCols = DEF_VISIBLE_COLS; private Scroller mScroller; private VelocityTracker mVelocityTracker; private int mCurRow = 0, mCurCol = 0; protected int mRowsCount = 0, mColsCount = 0; private static final int TOUCH_STATE_REST = 0; private static final int TOUCH_STATE_SCROLLING = 1; private static final int SNAP_VELOCITY = 600; private int mTouchState = TOUCH_STATE_REST; private int mTouchSlop; private float mLastMotionX, mLastMotionY; private MetroListener metroListener; protected ArrayList<MetroItem> mMetroItems = new ArrayList<MetroItem>(); private int mRowHeight, mColWidth; private int mGap = 0; // for long press event private boolean mHasPerformedLongPress; private CheckForLongPress mPendingCheckForLongPress; public MetroView(Context context) { this(context, null); } public MetroView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MetroView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); initViewGroup(context); } private void initViewGroup(Context context) { mScroller = new Scroller(context); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); setOnLongClickListener(longclickListener); } public void setGap(int gap) { mGap = gap; } /** * set row and column count for visible item 0 equals to not change current * value others equal to * * @param rowCount * @param colCount */ public void setVisibleItems(int rowCount, int colCount) { if (rowCount < 0 || colCount < 0) throw new IllegalArgumentException("visible count < 0"); if (rowCount != 0) visibleRows = rowCount; if (colCount != 0) visibleCols = colCount; } public int getVisibleRows() { return visibleRows; } public int getVisibleCols() { return visibleCols; } public void addMetroItem(MetroItem item) { mMetroItems.add(item); addView(item.getMetroView(), FILL_FILL); adjustRowCol(item); } public boolean deleteMetroItem(MetroItem item) { boolean ret = false; if (mMetroItems.contains(item)) { mMetroItems.remove(item); removeView(item.getMetroView()); ret = true; } mRowsCount = 0; mColsCount = 0; for (MetroItem mi : mMetroItems) { adjustRowCol(mi); } return ret; } private void adjustRowCol(MetroItem item) { // adjust rows count if (mRowsCount < item.getRow() + item.getRowSpan()) mRowsCount = item.getRow() + item.getRowSpan(); // adjust columns count if (mColsCount < item.getCol() + item.getColSpan()) mColsCount = item.getCol() + item.getColSpan(); } public void clearMetroItem() { mMetroItems.clear(); removeAllViews(); mRowsCount = 0; mColsCount = 0; } public void setOrientation(OrientationType orientation) { mOrientation = orientation; } public OrientationType getOrientation() { return mOrientation; } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { final int itemCount = mMetroItems.size(); if (itemCount != getChildCount()) throw new IllegalArgumentException("contain unrecorded child"); for (int i = 0; i < itemCount; i++) { final MetroItem item = mMetroItems.get(i); final View childView = item.getMetroView(); if (childView.getVisibility() != View.GONE) { final int childLeft = (mColWidth + mGap) * item.getCol(); final int childTop = (mRowHeight + mGap) * item.getRow(); final int childWidth = (mColWidth + mGap) * item.getColSpan() - mGap; final int childHeight = (mRowHeight + mGap) * item.getRowSpan() - mGap; childView.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); } } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int width = MeasureSpec.getSize(widthMeasureSpec); final int height = MeasureSpec.getSize(heightMeasureSpec); mRowHeight = (height - (visibleRows - 1) * mGap) / visibleRows; mColWidth = (width - (visibleCols - 1) * mGap) / visibleCols; // The children are given the same width and height as the scrollLayout final int itemCount = mMetroItems.size(); for (int i = 0; i < itemCount; i++) { final MetroItem item = mMetroItems.get(i); final View childView = item.getMetroView(); final int childWidth = MeasureSpec.makeMeasureSpec( (mColWidth + mGap) * item.getColSpan() - mGap, MeasureSpec.EXACTLY); final int childHeight = MeasureSpec.makeMeasureSpec( (mRowHeight + mGap) * item.getRowSpan() - mGap, MeasureSpec.EXACTLY); childView.measure(childWidth, childHeight); } scrollTo((mColWidth + mGap) * mCurCol, (mRowHeight + mGap) * mCurRow); } /** * According to the position of current layout scroll to the destination * page. */ public void snapToDestination() { final int destRow = (getScrollY() + (mRowHeight + mGap) / 2) / (mRowHeight + mGap); final int destCol = (getScrollX() + (mColWidth + mGap) / 2) / (mColWidth + mGap); snapTo(destRow, destCol); } public void snapTo(int whichRow, int whichCol) { if (whichRow < 0) whichRow = 0; if (whichCol < 0) whichCol = 0; Log.d(TAG, String.format("snap to row:%d, col:%d", whichRow, whichCol)); boolean needRedraw = false; if (mOrientation == OrientationType.Horizontal) { whichRow = 0; if (whichCol + visibleCols > mColsCount) whichCol = Math.max(mColsCount - visibleCols, 0); } else if (mOrientation == OrientationType.Vertical) { whichCol = 0; if (whichRow + visibleRows > mRowsCount) whichRow = Math.max(mRowsCount - visibleRows, 0); } else if (mOrientation == OrientationType.All) { if (whichRow + visibleRows > mRowsCount) whichRow = Math.max(mRowsCount - visibleRows, 0); if (whichCol + visibleCols > mColsCount) whichCol = Math.max(mColsCount - visibleCols, 0); } int deltaX = whichCol * (mColWidth + mGap); int deltaY = whichRow * (mRowHeight + mGap); // get the valid layout page if (getScrollX() != deltaX) { deltaX = deltaX - getScrollX(); needRedraw = true; } if (getScrollY() != deltaY) { deltaY = deltaY - getScrollY(); needRedraw = true; } if (needRedraw) { // only scroll one screen int startX = mColWidth; int startY = mRowHeight; if (deltaX > mColWidth) { startX = deltaX - mColWidth; deltaX = mColWidth; } else startX = getScrollX(); if (deltaY > mRowHeight) { startY = deltaY - mRowHeight; deltaY = mRowHeight; } else startY = getScrollY(); mScroller.startScroll(startX, startY, deltaX, deltaY, Math.max(Math.abs(deltaX), Math.abs(deltaY)) * 2); mCurRow = whichRow; mCurCol = whichCol; invalidate(); // Redraw the layout } } public int getCurRow() { return mCurRow; } public int getCurCol() { return mCurCol; } @Override public void computeScroll() { if (mScroller.computeScrollOffset()) { scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); postInvalidate(); } } @Override public boolean onTouchEvent(MotionEvent event) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); final int action = event.getAction(); float x = event.getX(); float y = event.getY(); if (mOrientation == OrientationType.Horizontal) y = 0; else if (mOrientation == OrientationType.Vertical) x = 0; switch (action) { case MotionEvent.ACTION_DOWN: if (!mScroller.isFinished()) { mScroller.abortAnimation(); } mLastMotionX = x; mLastMotionY = y; break; case MotionEvent.ACTION_MOVE: int deltaX = (int) (mLastMotionX - x); int deltaY = (int) (mLastMotionY - y); mLastMotionX = x; mLastMotionY = y; scrollBy(deltaX, deltaY); break; case MotionEvent.ACTION_UP: final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); int velocityY = (int) velocityTracker.getYVelocity(); int row = mCurRow; int col = mCurCol; if (velocityX > SNAP_VELOCITY && mCurCol > 0) { // Fling enough to move left col--; } else if (velocityX < -SNAP_VELOCITY && mCurCol < mColsCount - 1) { // Fling enough to move right col++; } if (velocityY > SNAP_VELOCITY && mCurRow > 0) { // Fling enough to move up row--; } else if (velocityY < -SNAP_VELOCITY && mCurRow < mRowsCount - 1) { // Fling enough to move down row++; } if (row == mCurRow && col == mCurCol) snapToDestination(); else { snapTo(row, col); if (metroListener != null) metroListener.scrollto(row, col); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; break; } return true; } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) { return true; } final float x = ev.getX(); switch (action) { case MotionEvent.ACTION_MOVE: final int xDiff = (int) Math.abs(mLastMotionX - x); if (xDiff > mTouchSlop) { mTouchState = TOUCH_STATE_SCROLLING; cancelLongClick(); } break; case MotionEvent.ACTION_DOWN: mLastMotionX = x; mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; if (isLongClickable()) postCheckForLongClick(); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mTouchState = TOUCH_STATE_REST; cancelLongClick(); break; } if (mHasPerformedLongPress) return true; else return mTouchState != TOUCH_STATE_REST; } private void postCheckForLongClick() { mHasPerformedLongPress = false; if (mPendingCheckForLongPress == null) mPendingCheckForLongPress = new CheckForLongPress(); postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout()); } private void cancelLongClick() { if (!mHasPerformedLongPress && mPendingCheckForLongPress != null) removeCallbacks(mPendingCheckForLongPress); } class CheckForLongPress implements Runnable { public void run() { if (performLongClick()) mHasPerformedLongPress = true; } } private OnLongClickListener longclickListener = new OnLongClickListener() { @Override public boolean onLongClick(View v) { longclickEvent(); return true; } }; /** * long click event */ protected void longclickEvent() { Log.d(TAG, "long click"); } public void setMereoListener(MetroListener metroListener) { this.metroListener = metroListener; } public interface MetroListener { public void scrollto(int row, int col); } }
- MetroUI.rar (407.6 KB)
- 下载次数: 123
发表评论
-
获取Android Device的信息
2013-12-26 15:47 1443String phoneInfo = "PROD ... -
看雪学院-Android安全
2013-11-25 09:40 942http://bbs.pediy.com/forumdispl ... -
Toast原来也可以多样化
2013-09-18 13:48 1163Style 1: 默认 Toast def = Toast ... -
Google Map API V2
2013-05-13 13:37 2156以后如果要开发包含google map的程序就更麻烦咯 htt ... -
用OpenGL实现无限循环的coverflow
2013-04-26 14:16 4781网上找了很久,都是用Gallery实现的,效果不是很满意,结果 ... -
如何集成支付宝官方文档
2013-02-08 11:24 4477官方文档下载地址 https://b.alipay.com/o ... -
[转帖]裁剪图片
2013-01-30 17:22 929原帖:http://www.linuxidc.com/Linu ... -
MonkeyRunner的使用
2013-01-29 13:06 9654要使用MonkeyRunner,就要 ... -
重复执行某段代码
2012-12-29 14:36 1562用handler就可以了 private Handler ... -
选择音频的输出方式
2012-12-12 15:00 1947可以选择用耳机还是扬声器播放(蓝牙的就留到下次吧),要求SDK ... -
使FrameLayout的Gravity等于Center
2012-12-06 16:42 1705由于无法设置FrameLayout的Gravity,所以只能通 ... -
Uri.Builder与String互转
2012-08-14 15:56 2289Uri.Builder -> String Uri. ... -
判断屏幕尺寸
2012-07-17 10:21 1849// support from API 4 final ... -
自己封装的支持自动对焦的CameraView
2012-07-12 13:52 3595import java.io.BufferedOutp ... -
ADT 离线包下载地址
2012-07-06 14:32 1989更新ADT真是件苦恼的事啊 20.0.0的下载地址 http ... -
通过Wifi实现设备间的通信
2012-06-05 15:19 1995服务器端,建立监听(方法更新,可以同时连接多个Client) ... -
IP地址的获取及解析
2012-06-05 13:31 1245获取IP地址 WifiManager wifiManage ... -
判断网络是否有效
2012-05-28 17:32 942protected boolean isInternetA ... -
悬浮窗
2012-05-28 17:21 3037类似于360监视网络速度的那个悬浮窗 public cl ... -
自定义全屏Dialog
2012-04-20 13:16 4004关键在于设置Style <style nam ...
相关推荐
安卓Android源码——MetroUI.zip
安卓Android源码——MetroUI.rar
This resource demonstrates a Metro UI inspired jQuery UI theme built with the jQUIT Builder.
metro ui css本身是兼容firefox、chrome、IE9的,我这边由于做界面加了些样式,目前这个demo在firefox下查看是好的,在chrome上看可能会有些样式排版问题,IE9没试。这个demo自己花了些时间做的,希望对正在学metro ...
Metro UI CSS 是高仿windows8 风格的一套不错样式框架。以上资源建议配合Metro UI CSS 学习笔记一起使用。
Android MetroUI源码.zip
VIUI 构建在Vue.js 2.X之上的Metro UI 风格的工具包
Android应用源码之MetroUI.zip
Windows8 Modern(Metro)界面程序管理工具。集离线部署、卸载、清理和破解于一身,并可对metro界面程序设置代理访问Internet,功能超强!
MetroUI
Android应用源码之MetroUI.zip项目安卓应用源码下载Android应用源码之MetroUI.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
Android高级应用源码-MetroUI.zip
VB.NET制作Windows8 MetroUI Form 风格界面!供大家参考!
android 源码学习
一些Metro风格的图片 Windows UI风格的图片 希望对做WP7,WP8,Win8等的同学有点帮助
SSRS 2012 Metro UI 高端报表开发技巧讲解,比较系统,值得学习
metro ui style html JS