android自定义view生命周期,android基础之自定义view
一、Custom View
1、view的繼承關系
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;
}
}
總結
以上是生活随笔為你收集整理的android自定义view生命周期,android基础之自定义view的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 金本位被什么取代
- 下一篇: 办理邮政储蓄银行卡需要什么 需要带什么办