編輯:關於Android編程
public class ResizeLayout extends FrameLayout { private OnkeyboardShowListener mChangedListener; private boolean misKeyboardshow = false; private RRSharedPreferences preferences; private int keyboardHeight = DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT); private final int THRESHOLD = 100; /** * @param context * @param attrs */ public ResizeLayout(Context context, AttributeSet attrs) { super(context, attrs); preferences = new RRSharedPreferences(context); } public static interface OnkeyboardShowListener { public void onKeyboardShow(); public void onKeyboardHide(); public void onKeyboardShowOver(); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (oldh - h > THRESHOLD) { //鍵盤彈出了 misKeyboardshow = true; keyboardHeight = oldh - h; preferences.putIntValue(Config.KEYBOARD_HIGHT, keyboardHeight); if (mChangedListener != null) { mChangedListener.onKeyboardShow(); } } else if (h < oldh && misKeyboardshow) { //鍵盤變高了 if (keyboardHeight == DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT)) { preferences.getIntValue(Config.KEYBOARD_HIGHT, DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT)); } if (keyboardHeight != DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT)) { keyboardHeight += oldh - h; preferences.putIntValue(Config.KEYBOARD_HIGHT, keyboardHeight); } if (mChangedListener != null) { mChangedListener.onKeyboardShow(); } } else if (h - oldh > THRESHOLD) { //鍵盤隱藏了 misKeyboardshow = false; if (mChangedListener != null) { mChangedListener.onKeyboardHide(); } } else if (h > oldh && misKeyboardshow) { //鍵盤收縮了 if (keyboardHeight == DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT)) { preferences.getIntValue(Config.KEYBOARD_HIGHT, DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT)); } if (keyboardHeight != DipUtil.calcFromDip(Config.DEFAULT_KEYBOARD_HIGHT)) { keyboardHeight -= h - oldh; preferences.putIntValue(Config.KEYBOARD_HIGHT, keyboardHeight); } if (mChangedListener != null) { mChangedListener.onKeyboardShow(); } } CommonUtil.log("NCS", "keyboard height:"+ keyboardHeight); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); CommonUtil.log("NCS", "top:" + top + "--bottom:" + bottom); if (mChangedListener != null && misKeyboardshow) { mChangedListener.onKeyboardShowOver(); } } public boolean isKeyboardShowing() { return misKeyboardshow; } public void setOnKeyboardShowListener(OnkeyboardShowListener listener) { mChangedListener = listener; } }
本文實例講述了Android開發之簡單文件管理器實現方法。分享給大家供大家參考,具體如下:這裡運用Java I/O、ListActivity、Dialog、Bitmap等
再做一個項目的時候,要求標題欄的標題再中間,樣式,字體大小都要自定義。左邊一個返回按鈕,一個關閉按鈕,右邊定義一個提交按鈕,有時候顯示有時候隱藏。因為原生的title標題
現在我目前知道可以獲取SharedPreferences實例的常用方法有三個: 1.通過Context的getSharedPreferences(String name,
最近做項目,有個一個需求,就是圓角進度條。效果圖如下。當時項目時間很緊,沒多去想怎麼實現最佳,就直接把美工給的圓角進度條裁剪成了四份。來做 Canvas 剪切繪制。這樣雖