EditText弹出输入键盘后页面往上顶的问题
2016-04-12 19:17
260 查看
解决方案:
1.在中AndroidManifest中设置相应的Activity为
参数介绍:
"adjustResize" 该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间 "adjustPan" 该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。
在选择了adjustResize后,页面还是会往上顶和变形,经过调试得出是 RelativeLayout和 layout_weight 导致的。
猜测是这两个是给控件动态分配空间的,所以当软键盘弹出时,会重新布局页面,导致页面变形。所以建议是有Edit时谨慎使用RelativeLayout 和layout_weight
最后的布局xml如下,用了FrameLayout和LinearLayout。
只在空view中使用layout_weight,用来调节分块的空间占比:
也可以参考:
http://2dxgujun.com/post/2014/10/23/Soft-Keyboard-Jacking-Control.html
1.在中AndroidManifest中设置相应的Activity为
android:windowSoftInputMode="adjustResize"
参数介绍:
"adjustResize" 该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间 "adjustPan" 该Activity主窗口并不调整屏幕的大小以便留出软键盘的空间。相反,当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分。这个通常是不期望比调整大小,因为用户可能关闭软键盘以便获得与被覆盖内容的交互操作。
在选择了adjustResize后,页面还是会往上顶和变形,经过调试得出是 RelativeLayout和 layout_weight 导致的。
猜测是这两个是给控件动态分配空间的,所以当软键盘弹出时,会重新布局页面,导致页面变形。所以建议是有Edit时谨慎使用RelativeLayout 和layout_weight
最后的布局xml如下,用了FrameLayout和LinearLayout。
只在空view中使用layout_weight,用来调节分块的空间占比:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout 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" tools:context="com.duotin.fm.activity.PlayLiveActivity"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.duotin.fm.widget.DTActionBar android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/transparent" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="230dp" android:layout_marginTop="50dp"> <ImageView style="@style/playerCircleImage" android:layout_centerInParent="true" android:src="@drawable/default_album_image_player"/> <include layout="@layout/real_live_count_down" android:layout_width="230dp" android:layout_height="230dp" android:layout_centerInParent="true" android:visibility="invisible"/> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.6" android:background="#00ffffff" /> <TextView android:layout_width="wrap_content" android:layout_height="40dp" android:layout_gravity="center_horizontal" android:background="@drawable/shp_real_live_rounded_retangle_some_transparant" android:gravity="center" android:minWidth="50dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:textSize="15dp" android:visibility="invisible"/> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#00ffffff" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginBottom="15dp" android:paddingLeft="10dp" android:paddingRight="10dp"> <ImageView android:layout_width="wrap_content" android:layout_height="40dp" android:layout_centerInParent="true" android:paddingLeft="15dp" android:paddingRight="15dp" android:src="@drawable/real_live_pause" android:visibility="invisible"/> <RelativeLayout android:layout_width="130dp" android:layout_height="40dp" android:layout_centerVertical="true" android:layout_toRightOf="@+id/ivPlayControlRL" android:background="@drawable/shp_real_live_rounded_retangle"> <ImageView android:layout_width="20dp" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_marginBottom="10dp" android:layout_marginLeft="12dp" android:layout_marginTop="10dp" android:src="@drawable/real_live_logo" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/ivBrandLogRL" android:gravity="center" android:paddingRight="10dp" android:singleLine="true" android:text="" android:textColor="@color/appOrange" android:textSize="12sp" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#00ffffff" /> <Button android:layout_width="130dp" android:layout_height="40dp" android:layout_centerInParent="true" android:layout_toLeftOf="@+id/ivPlayControlRL" android:background="@drawable/shp_real_live_rounded_retangle" android:gravity="center" android:paddingLeft="10dp" android:paddingRight="10dp" android:text="关闭弹幕" android:textColor="@color/appOrange" android:textSize="12sp" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#00ffffff" /> <View android:layout_width="match_parent" android:layout_height="63dp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="330dp"> <master.flame.danmaku.ui.widget.DanmakuView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="50dp"/> </LinearLayout> <RelativeLayout android:id="@+id/sendingTanMu" android:layout_width="match_parent" android:layout_height="63dp" android:layout_gravity="bottom" android:background="#FFEEEEEE" android:paddingBottom="10dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="43dp" android:layout_alignParentRight="true" android:background="@drawable/shp_real_live_right_rounded_retangle" android:gravity="center" android:padding="10dp" android:paddingRight="8dp" android:text="发送" android:textColor="@color/white" android:textSize="18sp"/> <EditText android:layout_width="match_parent" android:layout_height="43dp" android:layout_toLeftOf="@id/tvSendDanmaku" android:background="@drawable/shp_real_live_left_rounded_retangle" android:hint="你想说什么" android:paddingLeft="15dp" android:textColorHint="#FF9B9B9B" /> </RelativeLayout> </FrameLayout>
也可以参考:
http://2dxgujun.com/post/2014/10/23/Soft-Keyboard-Jacking-Control.html
相关文章推荐
- 华为AR3260忘记密码重置方法
- 池化方法总结(Pooling)
- Android登录客户端,验证码的获取,网页数据抓取与解析,HttpWatch基本使用
- %E2%80%8E Zero-Width Space
- ZZULI 1861: 斗破苍穹【回文字符串】
- 启用新博客地址
- solr入门之设计自己的Java本地缓存工具类
- struts2 利用 POI 导出 excel
- 虚拟现实外包公司— VR开发编辑器意义重大 印证VR不仅服务于用户
- 泛型集合遍历数据(里氏转换)
- 8猜数字
- python解析excel
- linux扩展根分区详细步骤
- 求n的因子的个数和。.
- 第6周项目1-分数类的雏形(2)
- mysql的loaddatainfile的用法
- 美团机器学习中的数据清洗与特征挖掘实践
- LeetCode之16----3Sums Closest
- LeetCode之16----3Sums Closest
- Python 优雅的操作字典