android自定义view生命周期,android基础之自定义view

一、Custom View

1、view的继承关系

a915a4560707?utm_campaign=maleskine&utm_content=note&utm_medium=pc_all_hots&utm_source=recommendation

view继承关系.png

2、Android 如何绘制试图层次

当activity获取焦点时,它必须提供layout层次的根节点,然后android 系统开始视图的绘制过程。绘制是从layout的根节点开始的,按照从上往下的顺序,父元素优先子元素。

绘制的两个过程:

measuring pass:实现measure(int,int)方法,顺序也是从上往下,每个view保存它自己的测量值

layout pass:实现layout(int,int,int,int)方法,顺序从上往下,在这个阶段每个layout manager负责他们各自所有子元素的位置,通过上一步测量的值

测量和绘制过程是交替进行的,layout manager可能运行 measure pass 若干次。例如 linearlayout需要支持weight属性,relativelayout需要测量子节点多次才能确定约束关系。

view或activity可以再次触发测量和绘制过程。通过 requestLayout()

在测量和布局计算完成后,视图就开始绘制自己。这个操作通过invalidate()触发。

3、view 截屏

每个view都支持创建当前显示状态的图片。

# Build the Drawing Cache

view.buildDrawingCache();

# Create Bitmap

Bitmap cache = view.getDrawingCache();

# Save Bitmap

saveBitmap(cache);

view.destroyDrawingCache();

二、自定义view

1、创建自定义view

通过继承view或它的子类,可以创建自定义view

通过onDraw()方法绘制视图,如果需要重新绘制,调用invalidate()触发onDraw()

如果定义自己的view,确保参考ViewConfiguration 类,它包含了一些常亮定义

2、测量

必须调用 setMeasuredDimenstion(int,int)设置结果

3、定义自定义 layout managers

通过继承ViewGroup

自定义layout manager 可以重写 onMeasure() 和 onLayout(),并且计算孩子元素的测量结果

测量孩子元素的大小通过measureChildWithMargins();

三、生命周期

一个视图会在它依附到一个已依附到window的布局结构时显示。

onAttachedToWindow() ,当window可以时调用

onDetachedFromWindow(),当视图从父元素中移除时调用(父元素必须依附到window)。例如当

activity被回收(finish()方法被调用)或者视图在listview中被回收。该方法可以用来停止动画和清理资源

四、定义自定义属性

xmlns:tools="http://schemas.android.com/tools"

xmlns:custom="http://schemas.android.com/apk/res/com.vogella.android.view.compoundview"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

>

android:layout_width="match_parent"

android:layout_height="?android:attr/listPreferredItemHeight"

custom:titleText="Background color"

custom:valueColor="@android:color/holo_green_light"

/>

package com.vogella.android.view.compoundview;

import android.content.Context;

import android.content.res.TypedArray;

import android.util.AttributeSet;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

public class ColorOptionsView extends View {

private View mValue;

private ImageView mImage;

public ColorOptionsView(Context context, AttributeSet attrs) {

super(context, attrs);

TypedArray a = context.obtainStyledAttributes(attrs,

R.styleable.Options, 0, 0);

String titleText = a.getString(R.styleable.Options_titleText);

int valueColor = a.getColor(R.styleable.Options_valueColor,

android.R.color.holo_blue_light);

a.recycle();

// more stuff

}

}

对于自定义属性中的format的值及其含义如下:

format属性值:reference 、color、boolean、dimension、float、integer、string、fraction、enum、flag

reference:参考某一资源ID。

(1)属性定义:

(2)属性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:background = "@drawable/图片ID"

/>

color:颜色值。

(1)属性定义:

(2)属性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:textColor = "#00FF00"

/>

boolean:布尔值。

(1)属性定义:

(2)属性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:focusable = "true"

/>

dimension:尺寸值。

(1)属性定义:

(2)属性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

/>

float:浮点值。

(1)属性定义:

(2)属性使用:

android:fromAlpha = "1.0"

android:toAlpha = "0.7"

/>

integer:整型值。

(1)属性定义:

(2)属性使用:

xmlns:android = "http://schemas.android.com/apk/res/android"

android:drawable = "@drawable/图片ID"

android:pivotX = "50%"

android:pivotY = "50%"

android:framesCount = "12"

android:frameDuration = "100"

/>

string:字符串。

(1)属性定义:

(2)属性使用:

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:apiKey = "0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"

/>

fraction:百分数。

(1)属性定义:

(2)属性使用:

xmlns:android = "http://schemas.android.com/apk/res/android"

android:interpolator = "@anim/动画ID"

android:fromDegrees = "0"

android:toDegrees = "360"

android:pivotX = "200%"

android:pivotY = "300%"

android:duration = "5000"

android:repeatMode = "restart"

android:repeatCount = "infinite"

/>

enum:枚举值。

(1)属性定义:

(2)属性使用:

xmlns:android = "http://schemas.android.com/apk/res/android"

android:orientation = "vertical"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent">

flag:位或运算。

(1)属性定义:

(2)属性使用:

android:name = ".StyleAndThemeActivity"

android:label = "@string/app_name"

android:windowSoftInputMode = "stateUnspecified |stateUnchanged | stateHidden">

特别要注意:

属性定义时可以指定多种类型值。

(1)属性定义:

(2)属性使用:

android:layout_width = "42dip"

android:layout_height = "42dip"

android:background = "@drawable/图片ID|#00FF00"

/>

下面说说AttributeSet与TypedArray在自定义控件中的作用:

AttributeSet的作用就是在控件进行初始化的时候,解析布局文件中该控件的属性(key eg:background)与该值(value eg:@drawable/icon)的信息封装在AttributeSet中,传递给该控件(View)的构造函数。对于非Android自带的属性,在View类中处理时是无法识别的,因此需要我们自己解析。所以这就要用到另外一个类TypedArray。在AttributeSet中我们有属性名称,有属性值,但是控件如何知道哪个属性代表什么意思呢?这个工作就由TypedArray来做了。TypedArray对象封装了/values/attrs.xml中的styleable里定义的每个属性的类型信息,通过TypedArray我们就可以知道AttributeSet中封装的值到底是干什么的了,从而可以对这些数据进行应用。

AttributeSet就相当于一盒糖,TypedArray就相当于这盒糖上的标签说明,告诉用户每个糖的口味等。这盒糖有什么口味是由用户自己的styleable文件里面的内容来决定的。

五、练习

在 res/values下创建文件attrs.xml

xmlns:tools="http://schemas.android.com/tools"

xmlns:custom="http://schemas.android.com/apk/res/com.vogella.android.view.compoundview"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:showDividers="middle"

android:divider="?android:attr/listDivider"

tools:context=".MainActivity" >

android:id="@+id/view1"

android:layout_width="match_parent"

android:layout_height="?android:attr/listPreferredItemHeight"

android:background="?android:selectableItemBackground"

android:onClick="onClicked"

custom:titleText="Background color"

custom:valueColor="@android:color/holo_green_light"

/>

android:id="@+id/view2"

android:layout_width="match_parent"

android:layout_height="?android:attr/listPreferredItemHeight"

android:background="?android:selectableItemBackground"

android:onClick="onClicked"

custom:titleText="Foreground color"

custom:valueColor="@android:color/holo_orange_dark"

/>

创建布局view_color_options.xml

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_centerVertical="true"

android:layout_marginLeft="16dp"

android:textSize="18sp"

/>

android:layout_width="26dp"

android:layout_height="26dp"

android:layout_centerVertical="true"

android:layout_marginLeft="16dp"

android:layout_marginRight="16dp"

/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="16dp"

android:layout_centerVertical="true"

android:visibility="gone"

/>

package com.vogella.android.customview.compoundview;

import com.vogella.android.view.compoundview.R;

import android.content.Context;

import android.content.res.TypedArray;

import android.util.AttributeSet;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

public class ColorOptionsView extends LinearLayout {

private View mValue;

private ImageView mImage;

public ColorOptionsView(Context context, AttributeSet attrs) {

super(context, attrs);

TypedArray a = context.obtainStyledAttributes(attrs,

R.styleable.ColorOptionsView, 0, 0);

String titleText = a.getString(R.styleable.ColorOptionsView_titleText);

int valueColor = a.getColor(R.styleable.ColorOptionsView_valueColor,

android.R.color.holo_blue_light);

a.recycle();

setOrientation(LinearLayout.HORIZONTAL);

setGravity(Gravity.CENTER_VERTICAL);

LayoutInflater inflater = (LayoutInflater) context

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

inflater.inflate(R.layout.view_color_options, this, true);

TextView title = (TextView) getChildAt(0);

title.setText(titleText);

mValue = getChildAt(1);

mValue.setBackgroundColor(valueColor);

mImage = (ImageView) getChildAt(2);

}

public ColorOptionsView(Context context) {

this(context, null);

}

public void setValueColor(int color) {

mValue.setBackgroundColor(color);

}

public void setImageVisible(boolean visible) {

mImage.setVisibility(visible ? View.VISIBLE : View.GONE);

}

}

package com.vogella.android.customview.compoundview;

import com.vogella.android.view.compoundview.R;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.widget.Toast;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.activity_main, menu);

return true;

}

public void onClicked(View view) {

String text = view.getId() == R.id.view1 ? "Background" : "Foreground";

Toast.makeText(this, text, Toast.LENGTH_SHORT).show();

}

}

-----------------------华丽的分割线---------------------

最后附上ViewConfiguration 类的源码

import android.app.AppGlobals;

import android.content.Context;

import android.content.res.Configuration;

import android.content.res.Resources;

import android.graphics.Point;

import android.os.RemoteException;

import android.provider.Settings;

import android.util.DisplayMetrics;

import android.util.SparseArray;

/**

* 主要用来获取一些在UI中所使用到的标准常量,像超时、尺寸、距离

*/

public class ViewConfiguration {

/**

* 定义了水平滚动条的宽度和垂直滚动条的高度,单位是dip

*/

private static final int SCROLL_BAR_SIZE = 10;

/**

* 滚动条褪去所需要经历的时间,单位:milliseconds

*/

private static final int SCROLL_BAR_FADE_DURATION = 250;

/**

* 滚动条褪去之前的默认时间延迟,单位:milliseconds

*/

private static final int SCROLL_BAR_DEFAULT_DELAY = 300;

/**

* 定义褪去边缘的长度,单位:dip

*/

private static final int FADING_EDGE_LENGTH = 12;

/**

* 按下状态在子控件上的持续时间,单位:milliseconds

*/

private static final int PRESSED_STATE_DURATION = 64;

/**

* 定义一个按下状态转变成长按状态所需要持续的时间,单位:milliseconds

*/

private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;

/**

* 定义连续重复按键间的时间延迟,单位:milliseconds

*/

private static final int KEY_REPEAT_DELAY = 50;

/**

* 如果用户需要触发全局对话框,例如:关机,锁屏等,需要按下按钮所持续的事件,单位:milliseconds

*/

private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;

/**

* 定义一个触摸事件是点击还是滚动的事件间隔,如果在这个事件内没有移动,就认为这是一个点击,否则就是滚动,单位:milliseconds

*/

private static final int TAP_TIMEOUT = 180;

/**

* Defines the duration in milliseconds we will wait to see if a touch event

* is a jump tap. If the user does not complete the jump tap within this interval, it is

* considered to be a tap.

*/

private static final int JUMP_TAP_TIMEOUT = 500;

/**

* 定义双击的时间间隔,如果在这个时间内,就认为是双击

*/

private static final int DOUBLE_TAP_TIMEOUT = 300;

/**

* 定义双击最小的时间间隔

*/

private static final int DOUBLE_TAP_MIN_TIME = 40;

/**

* 定义一个触摸板触摸到释放可认为是一个点击事件而不是一个触摸移动手势的最大时间,

* 也就是说在这个时间内进行一次触摸和释放操作就可以认为是一次点击事件,单位:milliseconds

*/

private static final int HOVER_TAP_TIMEOUT = 150;

/**

* 定义一个触摸板在触摸释放之前可以移动的最大距离,

* 如果在这个距离之内就可以认为是一个点击事件,否则就是一个移动手势,单位:pixels

*/

private static final int HOVER_TAP_SLOP = 20;

/**

* 定义响应显示缩放控制的时间

*/

private static final int ZOOM_CONTROLS_TIMEOUT = 3000;

/**

* Inset in dips to look for touchable content when the user touches the edge of the screen

*/

private static final int EDGE_SLOP = 12;

/**

* 如果我们认为用户正在滚动,这里定义一个触摸事件可以滚动的距离,单位:dips

* 注意:这个值在这里定义只是作为那些没有提供上下文Context来决定密度和配置相关值的应用程序的一个备用值。

*/

private static final int TOUCH_SLOP = 8;

/**

* 定义双击事件之间可以移动的距离,单位:dips

*/

private static final int DOUBLE_TAP_TOUCH_SLOP = TOUCH_SLOP;

/**

* 定义用户尝试翻页滚动的触摸移动距离,单位:dips

*

* 注意:这个值在这里定义只是作为那些没有提供上下文Context来决定密度和配置相关值的应用程序的一个备用值。

*

*/

private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;

/**

* 定义第一次点击和第二次点击可以认为是一次双击之间的距离。单位:dips

*/

private static final int DOUBLE_TAP_SLOP = 100;

/**

* Distance in dips a touch needs to be outside of a window's bounds for it to

* count as outside for purposes of dismissing the window.

*/

private static final int WINDOW_TOUCH_SLOP = 16;

/**

* 一个fling最小的速度,单位:dips/s

*/

private static final int MINIMUM_FLING_VELOCITY = 50;

/**

* 一个fling最大的速度,单位:dips/s

*/

private static final int MAXIMUM_FLING_VELOCITY = 8000;

/**

* 分发一个重复访问事件的延迟事件,单位:milliseconds

*/

private static final long SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS = 100;

/**

* The maximum size of View's drawing cache, expressed in bytes. This size

* should be at least equal to the size of the screen in ARGB888 format.

*/

@Deprecated

private static final int MAXIMUM_DRAWING_CACHE_SIZE = 480 * 800 * 4; // ARGB8888

/**

* 滚动和滑动的摩擦系数

*/

private static final float SCROLL_FRICTION = 0.015f;

/**

* Max distance in dips to overscroll for edge effects

*/

private static final int OVERSCROLL_DISTANCE = 0;

/**

* Max distance in dips to overfling for edge effects

*/

private static final int OVERFLING_DISTANCE = 6;

private final int mEdgeSlop;

private final int mFadingEdgeLength;

private final int mMinimumFlingVelocity;

private final int mMaximumFlingVelocity;

private final int mScrollbarSize;

private final int mTouchSlop;

private final int mDoubleTapTouchSlop;

private final int mPagingTouchSlop;

private final int mDoubleTapSlop;

private final int mWindowTouchSlop;

private final int mMaximumDrawingCacheSize;

private final int mOverscrollDistance;

private final int mOverflingDistance;

private final boolean mFadingMarqueeEnabled;

private boolean sHasPermanentMenuKey;

private boolean sHasPermanentMenuKeySet;

static final SparseArray sConfigurations =

new SparseArray(2);

/**

* 这个方法被废除了,使用ViewConfiguration.get(Context)}替代

*/

@Deprecated

public ViewConfiguration() {

mEdgeSlop = EDGE_SLOP;

mFadingEdgeLength = FADING_EDGE_LENGTH;

mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;

mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;

mScrollbarSize = SCROLL_BAR_SIZE;

mTouchSlop = TOUCH_SLOP;

mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;

mPagingTouchSlop = PAGING_TOUCH_SLOP;

mDoubleTapSlop = DOUBLE_TAP_SLOP;

mWindowTouchSlop = WINDOW_TOUCH_SLOP;

//noinspection deprecation

mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE;

mOverscrollDistance = OVERSCROLL_DISTANCE;

mOverflingDistance = OVERFLING_DISTANCE;

mFadingMarqueeEnabled = true;

}

/**

* 使用给定的context来创建一个新的配置。这个配置依赖于context里面不同的参数,例如显示的尺寸或者密度

* @param context 用来初始化这个view配置的应用上下文环境

*

* @see #get(android.content.Context)

* @see android.util.DisplayMetrics

*/

private ViewConfiguration(Context context) {

final Resources res = context.getResources();

final DisplayMetrics metrics = res.getDisplayMetrics();

final Configuration config = res.getConfiguration();

final float density = metrics.density;

final float sizeAndDensity;

if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) {

sizeAndDensity = density * 1.5f;

} else {

sizeAndDensity = density;

}

mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f);

mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f);

mMinimumFlingVelocity = (int) (density * MINIMUM_FLING_VELOCITY + 0.5f);

mMaximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);

mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);

mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);

mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f);

// Size of the screen in bytes, in ARGB_8888 format

final WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

final Display display = win.getDefaultDisplay();

final Point size = new Point();

display.getRealSize(size);

mMaximumDrawingCacheSize = 4 * size.x * size.y;

mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);

mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);

if (!sHasPermanentMenuKeySet) {

IWindowManager wm = WindowManagerGlobal.getWindowManagerService();

try {

sHasPermanentMenuKey = !wm.hasNavigationBar();

sHasPermanentMenuKeySet = true;

} catch (RemoteException ex) {

sHasPermanentMenuKey = false;

}

}

mFadingMarqueeEnabled = res.getBoolean(

com.android.internal.R.bool.config_ui_enableFadingMarquee);

mTouchSlop = res.getDimensionPixelSize(

com.android.internal.R.dimen.config_viewConfigurationTouchSlop);

mPagingTouchSlop = mTouchSlop * 2;

mDoubleTapTouchSlop = mTouchSlop;

}

/**

* 跟上面一个函数一样,只不过上面一个是创建一个ViewConfiguration对象,这里是直接通过这个静态方法返回一个对象

*/

public static ViewConfiguration get(Context context) {

final DisplayMetrics metrics = context.getResources().getDisplayMetrics();

final int density = (int) (100.0f * metrics.density);

ViewConfiguration configuration = sConfigurations.get(density);

if (configuration == null) {

configuration = new ViewConfiguration(context);

sConfigurations.put(density, configuration);

}

return configuration;

}

/**

* @return 获取水平滚动条的宽带和垂直滚动条的高度

*

* 这个函数被废除,使用getScaledScrollBarSize()来代替

*/

@Deprecated

public static int getScrollBarSize() {

return SCROLL_BAR_SIZE;

}

/**

* @return 获取水平滚动条的宽带和垂直滚动条的高度

*/

public int getScaledScrollBarSize() {

return mScrollbarSize;

}

/**

* @return 滚动条褪去的持续时间

*/

public static int getScrollBarFadeDuration() {

return SCROLL_BAR_FADE_DURATION;

}

/**

* @return 滚动条褪去的延迟时间

*/

public static int getScrollDefaultDelay() {

return SCROLL_BAR_DEFAULT_DELAY;

}

/**

* @return 褪去边缘的长度

*

* 这个方法已经废弃,用getScaledFadingEdgeLength()替代.

*/

@Deprecated

public static int getFadingEdgeLength() {

return FADING_EDGE_LENGTH;

}

/**

* @return 褪去边缘的长度,单位:pixels

*/

public int getScaledFadingEdgeLength() {

return mFadingEdgeLength;

}

/**

* @return 在子控件上按住状态的持续时间

*/

public static int getPressedStateDuration() {

return PRESSED_STATE_DURATION;

}

/**

* @return 按住状态转变为长按状态需要的时间

*/

public static int getLongPressTimeout() {

return AppGlobals.getIntCoreSetting(Settings.Secure.LONG_PRESS_TIMEOUT,

DEFAULT_LONG_PRESS_TIMEOUT);

}

/**

* @return 重新按键时间

*/

public static int getKeyRepeatTimeout() {

return getLongPressTimeout();

}

/**

* @return 重复按键延迟时间

*/

public static int getKeyRepeatDelay() {

return KEY_REPEAT_DELAY;

}

/**

* @return 判断用户是单击还是滚动的时间,在这个时间内没有移动则是单击,否则是滚动

*/

public static int getTapTimeout() {

return TAP_TIMEOUT;

}

/**

* @return the duration in milliseconds we will wait to see if a touch event

* is a jump tap. If the user does not move within this interval, it is

* considered to be a tap.

*/

public static int getJumpTapTimeout() {

return JUMP_TAP_TIMEOUT;

}

/**

* @return 得到双击间隔时间,在这个时间内,则是双击,否则就是单击

*/

public static int getDoubleTapTimeout() {

return DOUBLE_TAP_TIMEOUT;

}

/**

* @return the minimum duration in milliseconds between the first tap's

* up event and the second tap's down event for an interaction to be considered a

* double-tap.

*

* @hide

*/

public static int getDoubleTapMinTime() {

return DOUBLE_TAP_MIN_TIME;

}

/**

* @return the maximum duration in milliseconds between a touch pad

* touch and release for a given touch to be considered a tap (click) as

* opposed to a hover movement gesture.

* @hide

*/

public static int getHoverTapTimeout() {

return HOVER_TAP_TIMEOUT;

}

/**

* @return the maximum distance in pixels that a touch pad touch can move

* before being released for it to be considered a tap (click) as opposed

* to a hover movement gesture.

* @hide

*/

public static int getHoverTapSlop() {

return HOVER_TAP_SLOP;

}

/**

* @return Inset in dips to look for touchable content when the user touches the edge of the

* screen

*

* @deprecated Use {@link #getScaledEdgeSlop()} instead.

*/

@Deprecated

public static int getEdgeSlop() {

return EDGE_SLOP;

}

/**

* @return Inset in pixels to look for touchable content when the user touches the edge of the

* screen

*/

public int getScaledEdgeSlop() {

return mEdgeSlop;

}

/**

* @return Distance in dips a touch can wander before we think the user is scrolling

*

* @deprecated Use {@link #getScaledTouchSlop()} instead.

*/

@Deprecated

public static int getTouchSlop() {

return TOUCH_SLOP;

}

/**

* @return Distance in pixels a touch can wander before we think the user is scrolling

*/

public int getScaledTouchSlop() {

return mTouchSlop;

}

/**

* @return Distance in pixels the first touch can wander before we do not consider this a

* potential double tap event

* @hide

*/

public int getScaledDoubleTapTouchSlop() {

return mDoubleTapTouchSlop;

}

/**

* @return Distance in pixels a touch can wander before we think the user is scrolling a full

* page

*/

public int getScaledPagingTouchSlop() {

return mPagingTouchSlop;

}

/**

* @return Distance in dips between the first touch and second touch to still be

* considered a double tap

* @deprecated Use {@link #getScaledDoubleTapSlop()} instead.

* @hide The only client of this should be GestureDetector, which needs this

* for clients that still use its deprecated constructor.

*/

@Deprecated

public static int getDoubleTapSlop() {

return DOUBLE_TAP_SLOP;

}

/**

* @return Distance in pixels between the first touch and second touch to still be

* considered a double tap

*/

public int getScaledDoubleTapSlop() {

return mDoubleTapSlop;

}

/**

* Interval for dispatching a recurring accessibility event in milliseconds.

* This interval guarantees that a recurring event will be send at most once

* during the {@link #getSendRecurringAccessibilityEventsInterval()} time frame.

*

* @return The delay in milliseconds.

*

* @hide

*/

public static long getSendRecurringAccessibilityEventsInterval() {

return SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS;

}

/**

* @return Distance in dips a touch must be outside the bounds of a window for it

* to be counted as outside the window for purposes of dismissing that

* window.

*

* @deprecated Use {@link #getScaledWindowTouchSlop()} instead.

*/

@Deprecated

public static int getWindowTouchSlop() {

return WINDOW_TOUCH_SLOP;

}

/**

* @return Distance in pixels a touch must be outside the bounds of a window for it

* to be counted as outside the window for purposes of dismissing that window.

*/

public int getScaledWindowTouchSlop() {

return mWindowTouchSlop;

}

/**

* @return Minimum velocity to initiate a fling, as measured in dips per second.

*

* @deprecated Use {@link #getScaledMinimumFlingVelocity()} instead.

*/

@Deprecated

public static int getMinimumFlingVelocity() {

return MINIMUM_FLING_VELOCITY;

}

/**

* @return 得到滑动的最小速度, 以像素/每秒来进行计算

*/

public int getScaledMinimumFlingVelocity() {

return mMinimumFlingVelocity;

}

/**

* @return Maximum velocity to initiate a fling, as measured in dips per second.

*

* @deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.

*/

@Deprecated

public static int getMaximumFlingVelocity() {

return MAXIMUM_FLING_VELOCITY;

}

/**

* @return 得到滑动的最大速度, 以像素/每秒来进行计算

*/

public int getScaledMaximumFlingVelocity() {

return mMaximumFlingVelocity;

}

/**

* The maximum drawing cache size expressed in bytes.

*

* @return the maximum size of View's drawing cache expressed in bytes

*

* @deprecated Use {@link #getScaledMaximumDrawingCacheSize()} instead.

*/

@Deprecated

public static int getMaximumDrawingCacheSize() {

//noinspection deprecation

return MAXIMUM_DRAWING_CACHE_SIZE;

}

/**

* The maximum drawing cache size expressed in bytes.

*

* @return the maximum size of View's drawing cache expressed in bytes

*/

public int getScaledMaximumDrawingCacheSize() {

return mMaximumDrawingCacheSize;

}

/**

* @return The maximum distance a View should overscroll by when showing edge effects (in

* pixels).

*/

public int getScaledOverscrollDistance() {

return mOverscrollDistance;

}

/**

* @return The maximum distance a View should overfling by when showing edge effects (in

* pixels).

*/

public int getScaledOverflingDistance() {

return mOverflingDistance;

}

/**

* The amount of time that the zoom controls should be

* displayed on the screen expressed in milliseconds.

*

* @return the time the zoom controls should be visible expressed

* in milliseconds.

*/

public static long getZoomControlsTimeout() {

return ZOOM_CONTROLS_TIMEOUT;

}

/**

* The amount of time a user needs to press the relevant key to bring up

* the global actions dialog.

*

* @return how long a user needs to press the relevant key to bring up

* the global actions dialog.

*/

public static long getGlobalActionKeyTimeout() {

return GLOBAL_ACTIONS_KEY_TIMEOUT;

}

/**

* The amount of friction applied to scrolls and flings.

*

* @return A scalar dimensionless value representing the coefficient of

* friction.

*/

public static float getScrollFriction() {

return SCROLL_FRICTION;

}

/**

* Report if the device has a permanent menu key available to the user.

*

*

As of Android 3.0, devices may not have a permanent menu key available.

* Apps should use the action bar to present menu options to users.

* However, there are some apps where the action bar is inappropriate

* or undesirable. This method may be used to detect if a menu key is present.

* If not, applications should provide another on-screen affordance to access

* functionality.

*

* @return true if a permanent menu key is present, false otherwise.

*/

public boolean hasPermanentMenuKey() {

return sHasPermanentMenuKey;

}

/**

* @hide

* @return Whether or not marquee should use fading edges.

*/

public boolean isFadingMarqueeEnabled() {

return mFadingMarqueeEnabled;

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/245241.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python import如何使用_Python如何import其它.py文件及其函数

​ 如上图所示,我想在test_1.py文件中import我在lstm_1.py中定义的LstmParam和 LstmNetwork。我直接采用的是最简单的引用方法:from lstm_1 import LstmParam, LstmNetwork,但是很明显报错了,不能直接这样引用。因为,编…

艾为数字ic面试题_每日学习:数字后端面试100问(2019全新版)

关注并标星大同学吧每天1次,打卡学习积累1个新知识,增1分职场底气作者称谓:Tao涛个人介绍:摸爬滚打多年的数字后端工程师微信公众号:数字后端IC芯片设计半导体知识分享第29期技能升级,从这里开始最近项目刚…

not null primary key什么意思_explain都不会用,你还好意思说精通Mysql查询优化?

Explain简介Explain关键字是Mysql中sql优化的常用「关键字」,通常都会使用Explain来「查看sql的执行计划,而不用执行sql」,从而快速的找出sql的问题所在。在讲解Explain之前首先创建需要的「用户表user、角色表role、以及用户角色关系表role_…

docker always_Ubuntu+Docker+STF环境搭建

Ubuntu提前先安装配置好 Ubuntu server 14.04.5参考资料:Ubuntu 16.04 Server 版安装过程图文详解Dcoker安装Ubuntu 14.04/16.04 (使用apt-get进行安装)安装最新版本# step 1: 安装必要的一些系统工具安装指定版本# 安装指定版本的Docker-CE:安装校验rootubuntu:/ho…

导入obj_3D模型obj文件格式详解

3d打印机导入三维模型通常都是obj格式,下面我们来看一下这种文件的格式。为我们进行产品开发提供技术基础储备。obj格式有4种数据,分别以一下字母开头:v顶点vt纹理坐标vn顶点法向量f 面一、顶点格式:v x y z意义:每个顶…

import java.io 包下载_Go 包管理机制深入分析

前言随着 Go 语言的深入使用,其依赖管理机制也一直是各位 Gopher 热衷于探讨的话题。Go 语言的源码依赖可通过 go get 命令来获取,但自动化程度不高,于是官方提供了 Dep 这样的自动化批量管理依赖的工具。虽然 Go 语言的依赖管理在很多方面还…

android进出动画有白屏,Android启动白屏原因及解决方案

如果大家碰到了这个问题,相信刚开始大家都是很委屈的吧,心里想:我什么都没干啊,就写了个setContentView就要背锅了?如果已经遇到了,不要方,这里给大家提供几个解决方案,我们APP在启动…

jenkins 插件目录_三十二张图告诉你如何用Jenkins构建SpringBoot

目录前言如何安装Jenkins?环境准备开始安装Jenkins初始化配置访问首页输入管理员密码安装插件创建管理员实例配置配置完成构建Spring Boot 项目配置JDK、maven、Git环境安装插件添加 SSH Server添加凭据新建Maven项目构建任务如何构建托管在GitLab的项目&#xff1f…

filter过滤后重新添加_每天记一个单词(第3518)filter

filter /ˈfɪltər/ n. 过滤器;点击音频收听跟读 ↓↓↓↓↓↓(中慢速带读)(音频不显示请关闭头条app后台重新打开或者更新最新版本)英英解释:something that you pass water, air etc through in order to remove unwanted substances and make it clean or suita…

openwrt dhcp 无法获取ip_如何安装Openwrt软路由系统并配置正常使用

本篇文章教大家如何安装Openwrt软路由系统并配置正常使用。首先我们需要能用来当作软路由的主板,主板要至少需要2个千兆网口,一个用作Wan,其他用作Lan.我这边用到的是ASUS-N3050I-CM-A,这块主板拥有两个千兆网口,搭载了功耗仅6w的n3050 CPU,非…

android opencv 获取小图在大图的坐标_Android开发—基于OpenCV实现相机实时图像识别跟踪...

利用OpenCV实现实时图像识别和图像跟踪图像识别什么是图像识别图像识别,是指利用计算机对图像进行处理、分析和理解,以识别各种不同模式的目标和对像的技术。根据观测到的图像,对其中的物体分辨其类别,做出有意义的判断。利用现代…

三菱a系列motion软体_三菱M70A/64SM重要功能比较

三菱M70A/64SM重要功能比较M70A特有功能,64SM无法作到的功能往 期 精 选 1>三菱M70系统全清操作步骤2>三菱M70系统 程序传输操作步骤3>三菱M70分中对刀操作步骤4>三菱M70设置加工条件选择 介绍5>三菱M70系统 原点设定方法6>三菱M70/M700 用户参数…

centos 卸载_CentOS「linux」学习笔记12:磁盘管理、分区挂载卸载操作

linux基础操作:主要介绍了磁盘管理、分区挂载卸载操作。特别说明linux中磁盘表现形式:IDE硬盘在linux中表示方式为"hdx"。SCSI硬盘在linux中表示方式为"sdx"。这里的x代表磁盘号[a代表基本主磁盘(主盘)对应数字表示:1,b代…

html制作翻页效果代码,使用原生JS实现滚轮翻页效果的示例代码

一、滚轮事件当用户通过鼠标滚轮与页面交互、在垂直方向上滚动页面时,就会触发mousewheel事件,这个事件就是实现全屏切换效果需要用到的。在IE6, IE7, IE8, Opera 10, Safari 5中,都提供了 “mousewheel” 事件,而 Firefox 3.5 中…

python leetcode_Leetcode 常用算法 Python 模板

小 trickoverlap条件&#xff1a;start1 < end2 and end1 > start2 在DFS中我们说关键点是递归以及回溯&#xff0c;在BFS中&#xff0c;关键点则是状态的选取和标记树算法Binary Indexed Tree BIT 树状数组class BIT:def __init__(self, n):self.n n 1self.sums [0] …

画瀑布图_常见的招财风水画之含义

点击上方【觉悟法华】关注 风水画是指利于风水的字画&#xff0c;能起到招财、旺运、化煞等等的风水作用。那么&#xff0c;常见的招财风水画有哪些含义&#xff1f;大鹏展翅图&#xff1a;大鹏展翅图&#xff0c;通常挂在书房或者客厅&#xff0c;给人以一种“鹏程万里”、积极…

荣耀play4 pro怎么升级鸿蒙系统,华为鸿蒙系统手机型号有哪些

华为鸿蒙系统支持的手机型号有很多&#xff0c;如果你想第一时间升级鸿蒙系统&#xff0c;需要申请内测后&#xff0c;才能够下载安装升级哦&#xff01;不知道如何操作的小伙伴们&#xff0c;一起来看看趣丁网带来的华为鸿蒙os2.0系统怎么升级教程吧&#xff01;一、华为鸿蒙系…

shell脚本中取消高亮显示_Linux中强大的top命令

top命令算是最直观、好用的查看服务器负载的命令了。它实时动态刷新显示服务器状态信息&#xff0c;且可以通过交互式命令自定义显示内容&#xff0c;非常强大。在终端中输入top&#xff0c;回车后会显示如下内容&#xff1a;一、系统信息统计前五行是系统整体状态的统计信息展…

body onload 控制窗口大小 html,HTML5 对各个标签的定义与规定:body的介绍

HTML5 对各个标签的定义与规定&#xff1a;body的介绍2019年07月25日| 萬仟网IT编程| 我要评论本文主要介绍body标签... 12-06-21body元素就是就是html文档的主内容标签。可设置属性onafterprint 在打印文档之后运行脚本onbeforeprint 在文档打印之前运行脚本onbeforeonload 在…

html5手机电商网页设计代码_Html5网站制作,干货!20个视觉体验和内容俱佳的优秀网页设计...

如何创建一个网页&#xff1f;“Html5网站制作”和“灵感干货&#xff01;20个视觉、体验和内容俱佳的优秀网页设计”有什么关系和内在关联&#xff1f;在图片方面&#xff0c;有三个具体方案&#xff1a;图片地图、Css Sprites、内联图片三种&#xff0c;最值得关注的是 Css S…