Android输入法弹出时控制Listview
来源:互联网 发布:声音方位识别 软件 编辑:程序博客网 时间:2024/05/20 12:21
问题描述:类似微信聊天界面,输入法或者表情输入框显示时,listview自动显示最新一条消息
解决方法:
1、在AndroidManifest.xml文件的Activity中设置android:windowSoftInputMode=”adjustResize|stateAlwaysHidden”
2、重写了一个LinearLayout布局:
代码如下:
package com.example.listviewtest;import android.content.Context;import android.util.AttributeSet;import android.widget.LinearLayout;/** * Created by Administrator on 2016/8/11. */public class ResizeLayout extends LinearLayout { private OnResizeListener mListener; public interface OnResizeListener { void OnResize(); } public void setOnResizeListener(OnResizeListener l) { mListener = l; } public ResizeLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (mListener != null) { mListener.OnResize(); } }}
3.xml布局如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical"> <Button android:id="@+id/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="add" /> <com.example.listviewtest.ResizeLayout android:id="@+id/rslayout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="vertical"> <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </com.example.listviewtest.ResizeLayout> <Button android:id="@+id/more" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="more" /> <EditText android:id="@+id/edt_input" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true"/></LinearLayout>
4.在MainActivity中添加代码:
ResizeLayout rslayout;rslayout = (ResizeLayout) findViewById(R.id.rslayout); rslayout.setOnResizeListener(new ResizeLayout.OnResizeListener() { @Override public void OnResize() { listview.postDelayed(new Runnable() { @Override public void run() { listview.setSelection(listview.getCount()); listview.smoothScrollToPosition(listview.getCount()); } }, 100); } });
具体代码请参考附件:
0 0
- Android输入法弹出时控制Listview
- android TV盒子开发------控制editext弹出输入法
- Android 进入时屏蔽输入法自动弹出
- Android弹出关闭输入法
- activity打开时弹出或关闭输入法控制
- 【Android】【输入法】android 自动弹出输入法
- android 文本框输入法控制
- android 文本框输入法控制
- Android 输入法 控制 切换
- android输入法控制显示
- Android控制输入法
- Android控制输入法
- Android-- 输入法键盘控制
- android 输入法弹出键盘把listview顶上去,保留顶部标题栏位置不动
- Android弹出关闭输入法小记
- Android强制弹出,隐藏输入法.
- Android默认不弹出输入法
- Android的输入法是否弹出
- windows延迟关机命令
- hql(转载)(另一个版本)
- 关于同一页面多个swiper-container会出现swiper-pagenation总数多出的问题
- css选择器——:first/last-of-type
- 【每周至少一篇 160811】函数对象_Java
- Android输入法弹出时控制Listview
- java编程思想05
- 计蒜客 泥塑课
- 将表单内容转化成json字符串,并通过ajax提交!
- sublime text2-text3 定义的不同浏览器的预览快捷键
- iOS应用性能调优的25个建议和技巧
- 我需要你们的支持我才能变得火起来!
- 没解决的题
- 【NOIP2009提高组T3】最优贸易-双向SPFA