android开发应用知识,Android应用开发经常使用知识
在其它站點看到的,Mark一下
1、近期打開的應用不在近期任務列表中顯示
android:excludeFromRecents="true"
設(shè)置為true,則排除在近期任務列表之外,不在近期任務列表中顯示
2、推斷一個一個String str 是否為NULL或者是否為空字符串
TextUtils.isEmpty(str)
3、android:imeOptions="actionSearch|flagNoFullscreen"的使用方法
在做一個把EditText放到到ActionBar中作為搜索框的功能時,設(shè)置EditText的屬性為android:imeOptions="actionSearch",會遇到一個問題。當在橫屏時。EditText的寬度會填充掉屏幕上除了軟鍵盤之外的地方,與需求不符,改為android:imeOptions="actionSearch|flagNoFullscreen"后就OK了。
4、改變圖片亮度的方法
1、使用image.setColorFilter(Color.GRAY,PorterDuff.Mode.MULTIPLY);能夠使圖片變暗。然后使用image.clearColorFilter();清除濾鏡,恢復到原來的亮度。
2、使用
int brightness = -80;
ColorMatrix matrix = new ColorMatrix();
matrix.set(new float[] { 1, 0, 0, 0, brightness, 0, 1, 0, 0,
brightness, 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 });
v.setColorFilter(new ColorMatrixColorFilter(matrix));
但這樣的方法會使顏色不太正常。圖片留有黑邊。
5、用Handler來實現(xiàn)有時間間隔事件的推斷
看到Android中GestureDetector.java是用以下代碼實現(xiàn)手勢的單擊和雙擊推斷的:
public boolean onTouchEvent(MotionEvent ev) {
……
case MotionEvent.ACTION_DOWN:
if (mDoubleTapListener != null) {
boolean hadTapMessage = mHandler.hasMessages(TAP);
if (hadTapMessage) mHandler.removeMessages(TAP);
if ((mCurrentDownEvent != null) && (mPreviousUpEvent != null) && hadTapMessage &&
isConsideredDoubleTap(mCurrentDownEvent, mPreviousUpEvent, ev)) {
// This is a second tap
mIsDoubleTapping = true;
// Give a callback with the first tap of the double-tap
handled |= mDoubleTapListener.onDoubleTap(mCurrentDownEvent);
// Give a callback with down event of the double-tap
handled |= mDoubleTapListener.onDoubleTapEvent(ev);
} else {
// This is a first tap
mHandler.sendEmptyMessageDelayed(TAP, DOUBLE_TAP_TIMEOUT);
}
}
……
}
private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp,
MotionEvent secondDown) {
if (!mAlwaysInBiggerTapRegion) {
return false;
}
final long deltaTime = secondDown.getEventTime() - firstUp.getEventTime();
if (deltaTime > DOUBLE_TAP_TIMEOUT || deltaTime < DOUBLE_TAP_MIN_TIME) {
return false;
}
int deltaX = (int) firstDown.getX() - (int) secondDown.getX();
int deltaY = (int) firstDown.getY() - (int) secondDown.getY();
return (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare);
}
private class GestureHandler extends Handler {
GestureHandler() {
super();
}
GestureHandler(Handler handler) {
super(handler.getLooper());
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_PRESS:
mListener.onShowPress(mCurrentDownEvent);
break;
case LONG_PRESS:
dispatchLongPress();
break;
case TAP:
// If the user's finger is still down, do not count it as a tap
if (mDoubleTapListener != null) {
if (!mStillDown) {
mDoubleTapListener.onSingleTapConfirmed(mCurrentDownEvent);
} else {
mDeferConfirmSingleTap = true;
}
}
break;
default:
throw new RuntimeException("Unknown message " + msg); //never
}
}詳細能夠參考源代碼,這里是妙用了mHandler.sendEmptyMessageDelayed。假設(shè)在DOUBLE_TAP_TIMEOUT時間內(nèi)mHandler把TAP消息發(fā)送出去了。就是單擊時間,假設(shè)在這個時間內(nèi)沒有發(fā)送出去,就是雙擊事件。
總結(jié)
以上是生活随笔為你收集整理的android开发应用知识,Android应用开发经常使用知识的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 荣耀6手机升级android版本,华为荣
- 下一篇: android+模拟器皮肤,自定义and