Android输入法弹出时控制Listview
2016-08-11 18:41
441 查看
问题描述:类似微信聊天界面,输入法或者表情输入框显示时,listview自动显示最新一条消息
解决方法:
1、在AndroidManifest.xml文件的Activity中设置android:windowSoftInputMode=”adjustResize|stateAlwaysHidden”
2、重写了一个LinearLayout布局:
代码如下:
3.xml布局如下:
4.在MainActivity中添加代码:
具体代码请参考附件:
解决方法:
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); } });
具体代码请参考附件:
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories