XScrollView 自定义组件,使得被包含在其中的组件可以滑动,并且滑动后可以弹回到开始滑动的位置
来源:互联网 发布:mac虚拟机能玩游戏吗 编辑:程序博客网 时间:2024/06/06 02:08
XScrollView 自定义组件,使得被包含在其中的组件可以滑动,并且滑动后可以弹回到开始滑动的位置XScrollView
package org.busyboy.view;import android.content.Context;import android.util.AttributeSet;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.widget.LinearLayout;public class XScrollView extends LinearLayout {private float mLastY = 1; private String TAG = XScrollView.class.getName();private float margin =0 ;private final static float OFFSET_RADIO = 1.8f;public XScrollView(Context context) {super(context);}public XScrollView(Context context, AttributeSet attrs) {super(context, attrs);}@Overridepublic boolean onTouchEvent(MotionEvent ev) {if (mLastY == -1) {mLastY = ev.getRawY();}switch (ev.getAction()) {case MotionEvent.ACTION_DOWN:mLastY = ev.getRawY();break;case MotionEvent.ACTION_MOVE:final float deltaY = ev.getRawY() - mLastY;mLastY = ev.getRawY();margin += deltaY;updateHeaderHeight(margin);break;default:mLastY = -1; // resetresetHeaderHeight();break;}return true;}private void resetHeaderHeight() {Log.e(TAG , "resetHeaderHeight");Log.e(TAG , "count:"+this.getChildCount());View child = this.getChildAt(0);LinearLayout.LayoutParams param = (LayoutParams) child.getLayoutParams();param.topMargin = 0;child.setLayoutParams(param);margin=0;}private void updateHeaderHeight(float f) {Log.e(TAG , "updateHeaderHeight");Log.e(TAG , "count:"+this.getChildCount());View child = this.getChildAt(0);LinearLayout.LayoutParams param = (LayoutParams) child.getLayoutParams();param.topMargin = (int) (f*OFFSET_RADIO);child.setLayoutParams(param);}}
Demo:
<?xml version="1.0" encoding="utf-8"?><org.busyboy.view.XScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/xListView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff0000" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f0f0f0" android:gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="20dp" android:src="@drawable/ic_launcher" /> <EditText android:id="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:ems="10" android:hint="@string/username" > <requestFocus /> </EditText> <EditText android:id="@+id/pass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:ems="10" android:hint="@string/pass" android:inputType="textPassword" /> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:text="@string/login" /> </LinearLayout></org.busyboy.view.XScrollView>
0 0
- XScrollView 自定义组件,使得被包含在其中的组件可以滑动,并且滑动后可以弹回到开始滑动的位置
- 自定义平滑滑动页面的组件:DragableSpace
- 可以横向滑动竖向滑动的listview
- popwindow+viewpager+fragment并且可以滑动的问题
- 可以左右滑动的ListView
- 可以左右滑动的UITableView
- 可以左右滑动的柱形图
- Android自定义GridView显示一行,并且可以左右滑动
- 自定义组件实现可滑动的ToggleButton的功能..
- android自定义控件--条目可以左右滑动的listview
- 滑动时可以控制的动画 自定义ScrollView,LinearLayout
- Android自定义控件,可以滑动的导航栏(Navigation Bar)
- Android笔记09/07 自定义可以自由滑动的view
- Android 自定义可以滑动和点击的RangeBar
- android —— 自定义控件 竖向的ViewPager,上下滑动的组件,android上下滑动 VerticalPager
- 阻尼滑动--可以滑动过度的ScrollView(OverScrollView)
- 缩略图预览大图并且可以左右滑动
- 自定义ViewPager,使其不会左右滑动,解决在最后一页可以往回滑的问题
- ACM中java的使用
- 【android】Android 破解实例(一)
- hibernate 对象关系映射文件详解
- CPU 周期信号、节拍周期信号、节拍脉冲信号
- 关联容器
- XScrollView 自定义组件,使得被包含在其中的组件可以滑动,并且滑动后可以弹回到开始滑动的位置
- 微信聊天记录备份
- [chromium][browser][idea][closed]可独立安装的Android4.4.2 Browser + AwContent(SurfaceView方式 高性能模式)
- 基于按annotation的hibernate主键生成策略
- Android StringBuffer类
- hadoop学习【2】——hadoop安装配置
- MFC Socket中的Receive问题
- 最长回文子串
- 十二周-分析类中成员的访问属性