Android应用中出现软键盘遮挡住按钮如何解决

发布时间:2020-11-20 16:25:47

来源:亿速云

阅读:110

作者:Leah

Android应用中出现软键盘遮挡住按钮如何解决?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

如图:

实现1

xml

android:id="@+id/scrollview"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fadingEdge="none"

android:scrollbars="none">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:layout_width="100dp"

android:layout_height="100dp"

android:layout_gravity="center_horizontal"

android:layout_marginTop="20dp"

android:src="@mipmap/ic_loginhead"/>

android:id="@+id/et_usernamelogin_username"

android:layout_width="match_parent"

android:layout_height="40dp"

android:layout_marginTop="10dp"

android:background="@null"

android:hint="请输入已验证手机"

android:inputType="number"

android:lines="1"

android:maxLength="11"/>

android:layout_width="match_parent"

android:layout_height="2px"

android:layout_marginLeft="50dp"

android:layout_marginRight="50dp"

android:background="@color/pating_line"/>

android:id="@+id/et_usernamelogin_password"

android:layout_width="match_parent"

android:layout_height="40dp"

android:layout_marginTop="20dp"

android:background="@null"

android:digits="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_?"

android:hint="请输入密码"

android:inputType="textPassword"/>

android:layout_width="match_parent"

android:layout_height="2px"

android:layout_marginLeft="50dp"

android:layout_marginRight="50dp"

android:background="@color/pating_line"/>

android:id="@+id/btn_usernamelogin_dologin"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginLeft="50dp"

android:layout_marginRight="50dp"

android:layout_marginTop="30dp"

android:background="@drawable/btn_selecter"

android:enabled="false"

android:text="登录"

android:textColor="@color/white"

/>

java

mScrollView=(ScrollView)view.findViewById(R.id.scrollview);

usernamelogin_username.setOnTouchListener(newView.OnTouchListener(){

@Override

publicbooleanonTouch(Viewv,MotionEventevent){

changeScrollView();

returnfalse;

}

});

usernamelogin_password.setOnTouchListener(newView.OnTouchListener(){

@Override

publicbooleanonTouch(Viewv,MotionEventevent){

changeScrollView();

returnfalse;

}

});

/**

*使ScrollView指向底部

*/

privatevoidchangeScrollView(){

newHandler().postDelayed(newRunnable(){

@Override

publicvoidrun(){

mScrollView.scrollTo(0,mScrollView.getHeight());

}

},300);

}

实现2

xml同上

anim下新建gone.xml

android:fromXScale="1.0"

android:toXScale="0.0"

android:fromYScale="1.0"

android:toYScale="0.0"

android:pivotX="50%"

android:pivotY="50%"

android:duration="500"

android:repeatCount="0"/>

visiable.xml

android:fromXScale="0.0"

android:toXScale="1.0"

android:fromYScale="0.0"

android:toYScale="1.0"

android:pivotX="50%"

android:pivotY="50%"

android:duration="500"

android:repeatCount="0"/>

或者直接在代码中

importandroid.os.Bundle;

importandroid.os.Handler;

importandroid.support.v7.app.AppCompatActivity;

importandroid.view.KeyEvent;

importandroid.view.MotionEvent;

importandroid.view.View;

importandroid.view.animation.Animation;

importandroid.view.animation.AnimationSet;

importandroid.view.animation.ScaleAnimation;

importandroid.widget.Button;

importandroid.widget.EditText;

importandroid.widget.ImageView;

publicclassMainActivityextendsAppCompatActivity{

privateImageViewmHead;//头部ImageView

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mHead=(ImageView)findViewById(R.id.iv_head);

finalButtonbtn=(Button)findViewById(R.id.btn_usernamelogin_dologin);

finalEditTextet_pass=(EditText)findViewById(R.id.et_usernamelogin_password);

finalEditTextet_name=(EditText)findViewById(R.id.et_usernamelogin_username);

/**

*当输入被点击

*/

et_name.setOnTouchListener(newView.OnTouchListener(){

@Override

publicbooleanonTouch(Viewv,MotionEventevent){

start();

returnfalse;

}

});

btn.setEnabled(false);

btn.setOnClickListener(newView.OnClickListener(){

@Override

publicvoidonClick(Viewv){

}

});

}

privatevoidstart(){

AnimationSetanimationSet=newAnimationSet(true);

ScaleAnimationscaleAnimation=newScaleAnimation(

1,0.1f,1,0.1f,

Animation.RELATIVE_TO_SELF,0.5f,

Animation.RELATIVE_TO_SELF,0.5f);

scaleAnimation.setDuration(500);

animationSet.addAnimation(scaleAnimation);

animationSet.setFillAfter(true);

animationSet.setFillBefore(false);

animationSet.setRepeatCount(0);//设置重复次数

mHead.startAnimation(scaleAnimation);

newHandler().postDelayed(newRunnable(){

@Override

publicvoidrun(){

mHead.setVisibility(View.GONE);

}

},500);

}

/**

*菜单、返回键响应

*/

@Override

publicbooleanonKeyDown(intkeyCode,KeyEventevent){

//TODOAuto-generatedmethodstub

if(keyCode==KeyEvent.KEYCODE_BACK){

if(mHead.getVisibility()==View.GONE){

AnimationSetanimationSet=newAnimationSet(true);

ScaleAnimationscaleAnimation=newScaleAnimation(

0.1f,1f,0.1f,1f,

Animation.RELATIVE_TO_SELF,0.5f,

Animation.RELATIVE_TO_SELF,0.5f);

scaleAnimation.setDuration(500);

animationSet.addAnimation(scaleAnimation);

animationSet.setFillAfter(true);

animationSet.setFillBefore(false);

mHead.startAnimation(scaleAnimation);

mHead.setVisibility(View.VISIBLE);

}else{

finish();

}

}

returnfalse;

}

}

效果呢:

看完上述内容,你们掌握Android应用中出现软键盘遮挡住按钮如何解决的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

android 软键盘遮住按钮,Android应用中出现软键盘遮挡住按钮如何解决相关推荐

  1. 发送linux键盘消息,在C#程序中模拟发送键盘按键消息

    using System.Runtime.InteropServices; 引入键盘事件函数 [DllImport("user32.dll")] public static ext ...

  2. windows10添加键盘_如何在Windows中免费添加键盘并用您的语言书写

    windows10添加键盘 A lot of people don't realize that Windows supports a LOT of different languages out o ...

  3. 安装linux系统键盘布局,如何在 Linux 中使用屏幕键盘

    屏幕键盘可以作为实体键盘输入的替代方案.在某些时候,屏幕键盘显得非常需要. 比如, 你的键盘刚好坏了:你的机器太多,没有足够的键盘:你的机器没有多余的接口来连接键盘:你是个残疾人,打字有困难:或者你正 ...

  4. android经纬度是4.9e-324,百度定位中出现4.9E-324问题的原因和解决办法

    百度定位请查看官方开发文档 定位过程中出现经纬度为4.9E-324错误的可能情况,目前收集到四种: 1.权限错误 什么是权限错误呢?分为两种情况: 一是权限没有添加完全,没有从开发文档中完全拷贝到项目 ...

  5. android 存储空间监控,浅谈 Android 内存监控(中)

    前言 在上篇 浅谈 Android 内存监控(上) 中,我们聊了 LeakCanary,微信的 Matirx 和美团的 Probe,它们各自有不同的应用场景,例如,在开发测试环境,我们会偏向用 Lea ...

  6. 中机软云亮相2021青岛国际软件融合创新博览会现场

    9月24日至26日,2021青岛国际软件融合创新博览会在青岛国际会展中心隆重举行.2021青岛软博会在全面展示软件产业发展成果的同时,聚焦工业软件发展,加快青岛中国软件特色名城建设步伐,助力打造&qu ...

  7. js-移动端android浏览器中input框被软键盘遮住的问题解决方案

    我遇到的问题:在一个页面里有一个弹出层之前我给我的最外层加了固定定位 用了下面的方法也不好使:没有办法我将之改为绝对定位层级变高在加上一个顶部标签通过js计算顶部高度来实现满屏遮挡: <sect ...

  8. android虚拟键盘挡住布局,Android全屏时软键盘遮住输入框修改布局解决方案

    一般 *android:windowSoftInputMode="adjustResize" *就能解决软键盘遮住输入框的问题,但是当Activity设为Full Screen这个 ...

  9. android 自动 键盘,关于Android中的软键盘

    InputMethodService为我们的输入法创建了一个Dialog,并且将该Dialog的Window的某些参数(如Gravity)进行了设置,使之能够在底部或者全屏显示.当我们点击输入框时,系 ...

最新文章

  1. 面试造飞机系列:用心整理的HashMap面试题,以后都不用担心了
  2. b temia 外骨骼机器人_只能提高工作效率?现代外骨骼正在突破重重壁垒,走向融合的未来...
  3. spring boot actuator工作原理之http服务暴露源码分析
  4. VTK修炼之道78:交互与拾取_点拾取
  5. 反射和内省_单例设计模式–内省和最佳实践
  6. sum怎么用python_python sum()函数和.sum(axis=0)函数的使用
  7. @Inject 注入 还是报空指针
  8. dbcp连接池配置详解_重学MySQL:事务与连接池,一文详解带你搞懂
  9. response.setContentType(“text/html;charset=utf-8“)后依然乱码的解决方法
  10. 国标高数教材搞乱了微积分学界
  11. C语言及程序设计初级—分离整数与小数部分
  12. 机器学习-数据科学库 12 美国人口数据分析案例
  13. 100base-fx 单模/多模接口是什么意思
  14. Cubase中文版教程:如何通过音频剪辑软件创建工程
  15. 计算机校本培训措施,2017度信息技术校本培训计划
  16. Mac下安装Maven
  17. python二级成绩查询入口官网_python爬虫实战之模拟正方教务系统登录查询成绩
  18. hadoop - hadoop2.6 伪分布式 示例 wordcount 分词 和 hdfs常用操作命令
  19. Vista上StarForce驱动的卸载
  20. 水库安全监测主要包含什么内容(大坝安全监测、水雨情自动测报)

热门文章

  1. 原生 js前端路由系统实现3之代码 构建工具 和 querystring功能
  2. eclipse启动tomcat 404
  3. Unity3D调用摄像头显示当前拍摄画面
  4. nginx反向代理配置实例分享
  5. CentOS上安装mysql5.5.23
  6. nagios整合cacti2011版(五)
  7. Project查看资源分配情况
  8. jsp放在web-inf下的注意事项
  9. python高维数据_t-SNE高维数据可视化(python)
  10. jsp 嵌入java_关于JSP里的Java语句嵌入问题