关于软键盘弹出的问题
2012-10-11 10:50
183 查看
功能:当EditText获取焦点时先执行动画,执行完后,弹出软键盘,保证执行动画的流畅度
如果软键盘和动画同时执行,动画有卡的现象,用户体验不好
代码如下:
如果软键盘和动画同时执行,动画有卡的现象,用户体验不好
代码如下:
package com.example.chrombrower.view; import com.example.chrombrower.MainActivity; import com.example.chrombrower.R; import android.content.Context; import android.os.Handler; import android.text.InputType; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Scroller; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; public class TopEditTextView extends LinearLayout { private LinearLayout lay; private Scroller scroller,scroller_lay; private EditText editText; private int len; private int topLen; private Context c; public TopEditTextView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public TopEditTextView(Context context) { super(context); init(context); } private void init(Context context){ c=context; scroller=new Scroller(context); scroller_lay=new Scroller(context); View view=LayoutInflater.from(context).inflate(R.layout.top_view,null); lay=(LinearLayout) view.findViewById(R.id.tv_rl_lay); editText=(EditText) view.findViewById(R.id.tv_et_content); editText.setOnTouchListener(listener); this.addView(view,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); } private OnTouchListener listener=new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { editText.setInputType(InputType.TYPE_NULL); scroller.startScroll(len, 0, len, 0,500); scroller_lay.startScroll(0,0, topLen=-lay.getChildAt(2).getWidth()-40,0,1000); return false; } }; @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); lay.scrollTo(len=lay.getChildAt(0).getWidth()+5,0); } @Override public void computeScroll() { if(scroller_lay.computeScrollOffset()){ scrollTo(scroller_lay.getCurrX(),scroller.getCurrY()); //lay.scrollTo(scroller.getCurrX(), scroller.getCurrY()); postInvalidate(); if(scroller_lay.getCurrX()==topLen){ editText.setInputType(InputType.TYPE_CLASS_TEXT); editText.requestFocus(); InputMethodManager mgr = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE); mgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED); } } super.computeScroll(); } }
相关文章推荐
- 关于ListView中EditText在软键盘弹出后的焦点问题
- 关于弹出软键盘的问题
- 浅谈关于android软键盘弹出问题
- android关于EditText弹出软键盘的问题
- 关于ListView中EditText在软键盘弹出后的焦点问题
- 关于Android软键盘弹出,会把原来的界面挤上去的问题
- 关于程序进入包含EditText控件的界面会自动获取焦点并弹出软键盘影响用户体验的问题
- 关于ListView中EditText在软键盘弹出后的焦点问题
- 关于Android软键盘弹出,会把原来的界面挤上去的问题
- 关于ListView中EditText点击弹出软键盘及软键盘弹出后的焦点问题
- 关于webview点击输入框无法弹出软键盘问题
- 关于Android程序弹出软键盘的问题
- 关于Edittext点击弹出软键盘,布局上移标题消失问题,微信聊天界面
- 关于手机软键盘弹出挤压界面的问题
- 关于Edittext 弹出软键盘时 ListView背景被挤压的问题(已经解决)
- 关于移动端页面弹出框被软键盘遮挡的问题
- 关于软键盘弹出的问题
- [Android初级]关于如何解决软键盘弹出后覆盖界面布局的问题
- 关于Android软键盘弹出的问题
- 关于软键盘遮住屏幕和弹出软键盘把屏幕向上推的问题