- 浏览: 5838854 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (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
import android.content.Context; import android.graphics.Canvas; 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; /** * 仿Launcher中的WorkSapce,可以左右滑动切换屏幕的类 * @author Yao.GUET * blog: http://blog.csdn.net/Yao_GUET * date: 2011-05-04 */ public class ScrollLayout extends ViewGroup { private static final String TAG = "ScrollLayout"; private Scroller mScroller; private VelocityTracker mVelocityTracker; private int mCurScreen; private int mDefaultScreen = 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; private float mLastMotionY; public ScrollLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); // TODO Auto-generated constructor stub } public ScrollLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub mScroller = new Scroller(context); mCurScreen = mDefaultScreen; mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub if (changed) { int childLeft = 0; final int childCount = getChildCount(); for (int i=0; i<childCount; i++) { final View childView = getChildAt(i); if (childView.getVisibility() != View.GONE) { final int childWidth = childView.getMeasuredWidth(); childView.layout(childLeft, 0, childLeft+childWidth, childView.getMeasuredHeight()); childLeft += childWidth; } } } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Log.e(TAG, "onMeasure"); super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int width = MeasureSpec.getSize(widthMeasureSpec); final int widthMode = MeasureSpec.getMode(widthMeasureSpec); if (widthMode != MeasureSpec.EXACTLY) { throw new IllegalStateException("ScrollLayout only canmCurScreen run at EXACTLY mode!"); } final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY) { throw new IllegalStateException("ScrollLayout only can run at EXACTLY mode!"); } // The children are given the same width and height as the scrollLayout final int count = getChildCount(); for (int i = 0; i < count; i++) { getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec); } // Log.e(TAG, "moving to screen "+mCurScreen); scrollTo(mCurScreen * width, 0); } /** * According to the position of current layout * scroll to the destination page. */ public void snapToDestination() { final int screenWidth = getWidth(); final int destScreen = (getScrollX()+ screenWidth/2)/screenWidth; snapToScreen(destScreen); } public void snapToScreen(int whichScreen) { // get the valid layout page whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1)); if (getScrollX() != (whichScreen*getWidth())) { final int delta = whichScreen*getWidth()-getScrollX(); mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta)*2); mCurScreen = whichScreen; invalidate(); // Redraw the layout } } public void setToScreen(int whichScreen) { whichScreen = Math.max(0, Math.min(whichScreen, getChildCount()-1)); mCurScreen = whichScreen; scrollTo(whichScreen*getWidth(), 0); } public int getCurScreen() { return mCurScreen; } @Override public void computeScroll() { // TODO Auto-generated method stub if (mScroller.computeScrollOffset()) { scrollTo(mScroller.getCurrX(), mScroller.getCurrY()); postInvalidate(); } } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: Log.e(TAG, "event down!"); if (!mScroller.isFinished()){ mScroller.abortAnimation(); } mLastMotionX = x; break; case MotionEvent.ACTION_MOVE: int deltaX = (int)(mLastMotionX - x); mLastMotionX = x; scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP: Log.e(TAG, "event : up"); // if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); Log.e(TAG, "velocityX:"+velocityX); if (velocityX > SNAP_VELOCITY && mCurScreen > 0) { // Fling enough to move left Log.e(TAG, "snap left"); snapToScreen(mCurScreen - 1); } else if (velocityX < -SNAP_VELOCITY && mCurScreen < getChildCount() - 1) { // Fling enough to move right Log.e(TAG, "snap right"); snapToScreen(mCurScreen + 1); } else { snapToDestination(); } 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) { // TODO Auto-generated method stub Log.e(TAG, "onInterceptTouchEvent-slop:"+mTouchSlop); final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) { return true; } final float x = ev.getX(); final float y = ev.getY(); switch (action) { case MotionEvent.ACTION_MOVE: final int xDiff = (int)Math.abs(mLastMotionX-x); if (xDiff>mTouchSlop) { mTouchState = TOUCH_STATE_SCROLLING; } break; case MotionEvent.ACTION_DOWN: mLastMotionX = x; mLastMotionY = y; mTouchState = mScroller.isFinished()? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mTouchState = TOUCH_STATE_REST; break; } return mTouchState != TOUCH_STATE_REST; } }
import android.app.Activity; import android.os.Bundle; public class ScrollLayoutTest extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="text text" android:textColor="@android:color/white" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="ScrollLayout" android:textColor="@android:color/white" android:layout_weight="1" /> <com.yao_guet.test.ScrollLayout android:id="@+id/ScrollLayoutTest" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <LinearLayout android:background="#FF00" android:layout_width="fill_parent" android:layout_height="fill_parent"></LinearLayout> <FrameLayout android:background="#F0F0" android:layout_width="fill_parent" android:layout_height="fill_parent"></FrameLayout> <FrameLayout android:background="#F00F" android:layout_width="fill_parent" android:layout_height="fill_parent"> </FrameLayout> <LinearLayout android:background="#FF00" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button1" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" /> </LinearLayout> </com.yao_guet.test.ScrollLayout> </LinearLayout> </LinearLayout>
Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
http://blog.csdn.net/Yao_GUET/archive/2011/05/05/6397197.aspx
提取Launcher中的WorkSapce,可以左右滑动切换屏幕页面的类
http://blog.csdn.net/yao_guet/article/details/6393962
- ScrollLayoutTest.rar (48.3 KB)
- 下载次数: 378
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动.zip (65.1 KB)
- 下载次数: 279
- 类似android_桌面轮换的使用.rar (73.7 KB)
- 描述: 另一种效果
- 下载次数: 301
评论
4 楼
悠闲的鱼102104
2014-10-31





3 楼
llty
2011-11-23
好......。
2 楼
sunjunliangsunjun
2011-10-29
博主你好 ! 问题想请教一下 ! 如何监听ScrollLayout 的滑动事件!根据图片的id处理不同的数据!
1 楼
pisota
2011-07-05
这个不错,不过里边放TABHOST就有问题,不能切换TAB,只能显示一个TAB页里的内容,其他都是空白
发表评论
-
NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端
2018-10-31 20:45 7046网上有一个StickyScrollView,称之为粘性Scro ... -
自定义Behavior实现AppBarLayout越界弹性效果
2017-03-31 09:33 10411一、继承AppBarLayout.Beha ... -
Android - 一种相似图片搜索算法的实现
2017-03-31 09:33 2641算法 缩小尺寸。 将图片缩小到8x8的尺寸,总共64个 ... -
使用SpringAnimation实现带下拉弹簧动画的 ScrollView
2017-03-30 11:30 2876在刚推出的 Support Library 25.3.0 里面 ... -
Android为应用添加角标(Badge)
2017-03-30 11:21 62181.需求简介 角标是什么意思呢? 看下图即可明了: 可 ... -
Android端与笔记本利用局域网进行FTP通信
2017-03-23 10:17 1010先看图 打开前: 打开后: Activity类 ... -
PorterDuffColorFilter 在项目中的基本使用
2017-03-03 10:58 1376有时候标题栏会浮在内容之上,而内容会有颜色的变化,这时候就要求 ... -
ColorAnimationView 实现了滑动Viewpager 时背景色动态变化的过渡效果
2017-02-24 09:41 2245用法在注释中: import android.anima ... -
迷你轻量级全方向完美滑动处理侧滑控件SlideLayout
2017-01-16 16:53 2614纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 sup ... -
Effect
2017-01-05 09:57 0https://github.com/JetradarMobi ... -
动态主题库Colorful,容易地改变App的配色方案
2016-12-27 14:49 2589Colorful是一个动态主题库,允许您很容易地改变App的配 ... -
对视图的对角线切割DiagonalView
2016-12-27 14:23 1141提供对视图的对角线切割,具有很好的用户定制 基本用法 ... -
仿淘宝京东拖拽商品详情页上下滚动黏滞效果
2016-12-26 16:53 3561比较常用的效果,有现成的,如此甚好!:) import ... -
让任意view具有滑动效果的SlideUp
2016-12-26 09:26 1727基本的类,只有一个: import android.a ... -
AdvancedWebView
2016-12-21 09:44 16https://github.com/delight-im/A ... -
可设置圆角背景边框的按钮, 通过调节色彩明度自动计算按下(pressed)状态颜色
2016-11-02 22:13 1946可设置圆角背景边框的的按钮, 通过调节色彩明度自动计算按下(p ... -
网络请求库相关
2016-10-09 09:35 62https://github.com/amitshekhari ... -
ASimpleCache一个简单的缓存框架
2015-10-26 22:53 2201ASimpleCache 是一个为android制定的 轻量级 ... -
使用ViewDragHelper实现的DragLayout开门效果
2015-10-23 10:55 3448先看一下图,有个直观的了解,向下拖动handle就“开门了”: ... -
保证图片长宽比的同时拉伸图片ImageView
2015-10-16 15:40 3755按比例放大图片,不拉伸失真 import android. ...
相关推荐
本文将详细讲解如何通过自定义`ScrollLayout`来实现一个结合了两者功能的组件,使得用户既能左右滑动切换页面,也能上下滑动查看页面内的详细内容。这种设计常见于阅读应用或长内容展示场景。 首先,我们了解`...
在Android开发中,`ScrollLayout`通常指的是一个可滚动的布局容器,它可以包含多个子视图,并允许用户通过手势进行水平...通过这个过程,开发者可以学习到如何自定义Android UI组件,提升对Android系统底层机制的认识。
在实际开发中,ScrollLayout常常与其他组件结合使用,如ViewPager或Fragment,以实现更复杂的功能。例如,结合ViewPager可以创建一个可以滑动切换的Tab布局,每个Tab对应一个Fragment,这样既能保持界面清晰,又能...
总结来说,"scrolllayout"在Android开发中涉及到HorizontalScrollView的使用,手势识别(GestureDetector)来处理滑动事件,以及可能的ViewPager2和自定义PageTransformer实现平滑过渡和无限循环的效果。这些技术...
首先,我们关注的是`ScrollLayout`这个文件,它很可能是自定义的一个布局组件,用于实现滑动切换的效果。在Android中,通常我们会用到`ViewPager`或者自定义的`ViewGroup`来完成类似的功能。`ViewPager`是Android ...
抽屉效果通常通过Android的SlidingPaneLayout或者NavigationView来实现,但在这个项目中,开发者可能自定义了一个名为ScrollLayout的组件来达到更灵活的控制和定制。ScrollLayout-master这个文件名暗示了它是项目的...
压缩包中的`ScrollLayout`可能是一个自定义布局类,扩展了`LinearLayout`或`FrameLayout`,并添加了滑动手势检测和页面切换逻辑。它可能包含一个`ViewPager`实例,或者直接实现了滑动逻辑。 4. **手势检测**: ...
在这个案例中,`ScrollLayout`可能是开发者用来封装滑动抽屉逻辑的自定义组件,它可能继承自`LinearLayout`或`FrameLayout`等基础布局,并且添加了额外的滑动手势处理和动画效果。 描述中的“高德地图滑动效果”...
ScrollLayout是一种自定义的滚动布局,它允许在一个父布局中嵌套多个子视图,并且可以实现上下、左右的滑动效果。在这个项目中,ScrollLayout将被用来承载地图和其他UI元素,使得用户能够通过滑动来浏览内容。 1. *...
6. **事件监听**:可以通过`OnScrollChangeListener`监听`ScrollView`的滚动事件,实现自定义的功能,例如在滚动到底部时加载更多数据。 7. **滚动动画**:可以使用`ObjectAnimator`或`ValueAnimator`来创建滚动...
4. 设置ScrollLayout:将ListView或RecyclerView添加到ScrollView中,使整个列表可滚动。注意,由于ScrollView已经包含了滚动机制,所以一般不建议在ScrollView内部使用可以滚动的组件(如ListView),因为这可能...
android:id="@+id/ScrollLayout" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:layout_width="fill_parent" android:layout_height="fill_parent" android:background...
1. **使用自定义布局**:`ScrollLayout` 提示这是一个自定义的滚动布局,它允许开发者创建多页的滑动内容。在Android中,可以继承`ViewGroup`并重写`onMeasure()`和`onLayout()`方法来实现自定义布局。每个页面通常...
首先,我们需要理解`DrawerLayout`是Android系统提供的一个视图组件,它常用于实现滑动抽屉效果,通常用作导航菜单。抽屉可以从屏幕左侧或右侧滑出,为用户提供更多的操作选项。在Android Studio中,可以通过拖拽或...
- **自定义小部件**:开发可扩展的小部件接口,允许用户在主屏幕上添加各种功能组件。 - **动画效果**:为启动器的切换、拖放等操作添加平滑的过渡动画。 3. **LauncherDemo项目分析** "LauncherDemo"很可能是该...
- `MiLaucherActivity$4$1.class`和`DragGrid$2.class`、`DragGrid$1.class`:这些是内部类,可能与事件监听器或特定功能的实现有关,例如监听拖放操作或自定义布局的滚动事件。 5. **适配器类**:`DateAdapter....
对于UI的分析,oschina客户端的首页由多个组件构成,包括顶部的`main_header`、可滑动的`ScrollLayout`,以及底部菜单对应的四个页面(资讯、问答、动弹、我的空间)。每个部分都有相应的布局文件,如`main_header`...
在微信小程序开发中,`scroll-view` 是一个非常重要的组件,它允许开发者创建可滚动的内容区域,以处理超出屏幕范围的内容。本实例主要讲解如何利用 `scroll-view` 实现自动滑动到底部的功能,这对于聊天界面、评论...