[Android] 解决因键盘和表情panel显示/隐藏引起的闪屏
来源:互联网 发布:java多线程上传文件 编辑:程序博客网 时间:2024/05/16 07:05
在实现一些IM页面,例如对话框,评论框时,常常会遇到键盘和表情panel显示/隐藏引起的闪屏问题。问题的根本原因是当键盘收起或弹出时,layout会发生变化,此时panel的高度的计算如果时机不对,那么会导致闪屏。解决的办法有很多,这里提供一种重写onMeasure方法的实现:使用方法:// mCommentPanelLayout.showKeyboard(); // 当什么都没弹起的时候,点击按钮显示panel或者keyboard } } });layout是这样的:mEditText = (EditText) findViewById(R.id.editText); mPanel = (ViewGroup) findViewById(R.id.emotion_panel); mCommentPanelLayout = (CommentPanelLayout) findViewById(R.id.comment_panel_layout); mCommentPanelLayout.setListener(new CommentPanelLayout.SimpleListener() { @Override public void onKeyboardShow(View view) { Log.d(TAG, "onKeyboardShow() called"); } @Override public void onKeyboardHide(View view) { Log.d(TAG, "onKeyboardHide() called"); } @Override public void onPanelShow(View view) { Log.d(TAG, "onPanelShow() called"); } @Override public void onPanelHide(View view) { Log.d(TAG, "onPanelHide() called"); } }); mCommentPanelLayout.setFocusTarget(mEditText); // 设定要监听的edittext mCommentPanelLayout.setPanelView(mPanel); // 设定panel对象 findViewById(R.id.emotion_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mCommentPanelLayout.isKeyboardShown()) { mCommentPanelLayout.switchToPanel(); } else if (mCommentPanelLayout.isPanelShown()){ mCommentPanelLayout.switchToKeyboard(); } else if (!mCommentPanelLayout.isKeyboardShown() && !mCommentPanelLayout.isPanelShown()){ mCommentPanelLayout.showPanel();
源码如下所示:<your.package.CommentPanelLayout app:layout_constraintBottom_toBottomOf="parent" android:id="@+id/comment_panel_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/darker_gray"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="42dp" android:gravity="center_vertical" android:layout_toLeftOf="@+id/emotion_button" android:hint="make a comment..." android:paddingLeft="10dp" android:paddingStart="10dp"/> <Button android:layout_alignParentEnd="true" android:id="@+id/emotion_button" android:text="emotion" android:layout_width="wrap_content" android:layout_height="42dp"/> </RelativeLayout> <RelativeLayout android:visibility="gone" android:id="@+id/emotion_panel" android:layout_width="match_parent" android:layout_height="150dp"> <Button android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is a button"/> </RelativeLayout></your.package.CommentPanelLayout>
查看原文:http://legendmohe.net/2017/12/08/android-%e8%a7%a3%e5%86%b3%e5%9b%a0%e9%94%ae%e7%9b%98%e5%92%8c%e8%a1%a8%e6%83%85panel%e6%98%be%e7%a4%ba%e9%9a%90%e8%97%8f%e5%bc%95%e8%b5%b7%e7%9a%84%e9%97%aa%e5%b1%8f/
阅读全文
0 0
- [Android] 解决因键盘和表情panel显示/隐藏引起的闪屏
- Android监听键盘的显示和隐藏
- Android 输入法键盘的隐藏和显示
- Android 键盘的显示和隐藏
- Android edittext键盘的隐藏和显示
- android显示和隐藏键盘
- Android显示和隐藏键盘
- 键盘的显示和隐藏
- 解决android timePicker 和 datePicker因系统版本差异而引起的样式改变
- 解决Android因加载多个大图引起的OutOfMemoryError
- 完美解决因scrollview和recycleview引起的滑动冲突
- Android开发:输入法键盘的显示和隐藏
- android 系统键盘的控制(显示和隐藏)
- android解决加载webview时因缓存引起的白屏
- Android监听键盘显示和隐藏
- Android中如何显示和隐藏键盘
- Android监听键盘显示和隐藏
- android 中显示和隐藏键盘
- 7.配置服务器(config)
- 关于跨域请求和JSONP
- 权限的设计
- C/C++作业3
- 安装dos2unix
- [Android] 解决因键盘和表情panel显示/隐藏引起的闪屏
- 第一次写博客--记录一下javascript插件开发的内容
- 解决 error: style attribute '@android:attr/windowEnterAnimation' not found.
- 698. Partition to K Equal Sum Subsets
- 支付宝登录 支付
- Netty5.0(上)
- Python处理xlsx文件
- Linux 访问 Windows 代理服务器配置
- 菜鸟Linux攻略--目录文件权限的查看和修改(详细)