- 浏览: 702627 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
葫芦瓢:
葫芦瓢 写道专注IT 写道请问楼主demo中为什么是Custo ...
Android Scroller简单用法 -
葫芦瓢:
专注IT 写道请问楼主demo中为什么是CustomView中 ...
Android Scroller简单用法 -
u011493452:
注册账号给楼主点赞!
Android Scroller简单用法 -
jiduoduo:
整理的不错!
Android文件存储 -
xiaofeng0817166:
http://deerchao.net/tutorials/r ...
Java正则表达式应用
在Android UI中,我们常常会使用EditText,当用户点击这个EditText时会触发软键盘,这个软键盘会把EditText以下的界面挡住,有时候我们希望用户看到完整的界面,就像下图这样:
原理很简单,将布局的最外层添加一个ScrollView,当用户点击EditText时,将ScrollView滚动到底,废话不说,直接上代码
AndroidMainfest.xml
在布局页面中,我们在最外层使用了ScrollView,由于软键盘的弹出,原有界面从新布局,使得用户可以滚动界面。
main.xml
下面是代码的逻辑部分,比较简单
原理很简单,将布局的最外层添加一个ScrollView,当用户点击EditText时,将ScrollView滚动到底,废话不说,直接上代码
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ipjmc.demo.inputmethod" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".InputMethodActivity" <!--只有用户点击了编辑框才显示软键盘,并且会导致原有界面重新布局--> android:windowSoftInputMode="stateHidden|adjustResize" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
在布局页面中,我们在最外层使用了ScrollView,由于软键盘的弹出,原有界面从新布局,使得用户可以滚动界面。
main.xml
<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/scroll" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:text="@string/hello" android:textColor="#000" android:layout_width="fill_parent" android:layout_height="300dip" android:background="#0000FF" /> <EditText android:id="@+id/edit" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:id="@+id/button" android:text="提交" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </ScrollView>
下面是代码的逻辑部分,比较简单
package com.ipjmc.demo.inputmethod; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.Button; import android.widget.EditText; import android.widget.ScrollView; import android.util.Log; import android.view.View; public class InputMethodActivity extends Activity implements View.OnClickListener { private static final String TAG = "Scroll"; private EditText mEdit; private Button mButton; private ScrollView mScrollView; private Handler mHandler = new Handler(); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mScrollView = (ScrollView) findViewById(R.id.scroll); mEdit = (EditText) findViewById(R.id.edit); mButton = (Button) findViewById(R.id.button); mEdit.setOnClickListener(this); } @Override public void onClick(View v) { //这里必须要给一个延迟,如果不加延迟则没有效果。我现在还没想明白为什么 mHandler.postDelayed(new Runnable() { @Override public void run() { //将ScrollView滚动到底 mScrollView.fullScroll(View.FOCUS_DOWN); } }, 100); } }
发表评论
-
Android Notification的使用
2012-10-20 19:28 9722Android 4.1 (Jelly Bean ... -
短信拦截
2012-09-25 20:40 2037最近写一个应用(A),需要拦截短信分析。一般是 ... -
Android Scroller简单用法
2012-08-01 16:35 65768Android里Scroller类是为了实现Vi ... -
Android 使用WebView.loadData中文乱码解决办法
2012-07-19 15:09 9547博主在使用WebView的loadData方法时发 ... -
Android HttpClient基本使用方法
2012-07-05 14:15 107833这里只介绍如何使用HttpClient发起GET或者POST请 ... -
Android XML定义颜色
2012-06-09 13:15 0在res/colors.xml中添加如下代码: 定义C ... -
Activity和Task的设计思路和方法
2012-03-29 20:20 1196Activity和 Task是 Android ... -
显示PopupWindow
2012-03-16 10:04 16632PopupWindow可 ... -
存储文件的ContentProvider
2012-03-08 23:37 9338基于SQLite的ContentProvider ... -
Android文件存储
2012-03-08 22:34 19357Internal Storage内部存储空 ... -
Android 使用Notification
2012-03-07 10:26 2190用惯了Android的人在刚拿到iPhone的 ... -
onInterceptTouchEvent和onTouchEvent调用时序
2012-02-11 23:42 1038onInterceptTouchEvent() ... -
使用ConnectivityManager监听网络状态变化
2011-12-24 11:16 29791mIntenFilter = new IntentFilte ... -
Window Manager
2012-03-22 23:51 1520Android的窗口机制基于WindowManager,可以通 ... -
CommonsWare Android Components
2011-12-17 16:10 1714CommonsWare Android Com ... -
Android中图片缩放
2011-12-17 00:09 1882下载的图片如果过大,可能导致内存溢出。需要做压 ... -
Android 使用Parcelable序列化对象
2011-12-16 23:43 36513Android序列化对象主要有两种方法,实现S ... -
PreferenceActivity
2011-12-12 22:54 878传送门:http://www.cnblogs.com/wser ... -
View.scrollBy()与View.scrollTo()的使用
2011-12-12 22:40 19533scrollTo()和scrollBy()都是V ... -
Android 新浪微博授权
2011-12-11 17:13 7468OAuth方式 通过网页方式授权 实现方法,三个步骤 1.使用 ...
相关推荐
android 软键盘把界面顶起的问题 ,研究大半天,希望对大家有帮助。
Android自定义软键盘,在Keyboard的基础上稍微修改了一下,从键盘焦点效果到键盘布局,都是新风格。
检测软键盘是否显示或隐藏的功能。blog:http://blog.csdn.net/hehaiminginadth/article/details/48435703
Android仿微信聊天界面,解决软键盘抬升的小Demo。同时也有包含两张聊天气泡图。对应介绍博客[](https://blog.csdn.net/Allen_Adolph/article/details/106467315)。大家可以看看。谢谢支持!
android 关闭软键盘
android解决软键盘遮挡输入框的示例代码
Unity3D android 拉起android软键盘 最近公司项目有一个手机VR展厅业务,用U3D做VR场景还可以做到,后面要加个2D的线下预定页面,就涉及到3D 2D界面转换,首先考虑u3d作为插件,不考虑升级客户端,更新U3D资源来升级...
android软键盘把布局顶上去问题,包含全屏状态布局上移问题。
监听Android软键盘弹出和收起事件(所有代码都是抽离自facebook/react-native源码中, 亲测有效, 放心食用)。回调事件方法参数包含键盘是否弹出(isShow)、键盘高度(keyboardHeight)、屏幕可用高度(screenHeight)、屏幕...
在开发时遇到一个问题,需要对软...但是由于android不直接提供对软键盘打开与关闭操作的监听器,所以必须自己来写一个关于软键盘打开/关闭的监听器。 原理是通过对OnGlobalLayoutListener()来实现对软键盘的状态监听器
Android 实现软键盘与EditText的交互
android软键盘上添加一个按钮
android自定义软键盘键盘 系统键盘源码 两款android软件键盘 供大家参考学习
通过重写onLayout方法,判断软键盘是否弹出。判断到键盘是否弹出后,就可以做自己想做的事情了。
NULL 博文链接:https://dadi520.iteye.com/blog/2211109
Android自定义输入法软键盘,博客地址: https://blog.csdn.net/DeMonliuhui/article/details/84589936
android 监听软键盘状态(弹起还是收起),你懂的,没有现成的方法,通过跟布局的高度判断。
Android 底部控件随软键盘弹出而上移demo