国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

EditText彈出軟鍵盤后布局上移問題

2019-11-09 14:43:06
字體:
來源:轉載
供稿:網友

本文參考:

http://2dxgujun.com/post/2014/10/23/Soft-Keyboard-Jacking-Control.html

解決其文章的后續其他問題: 這個是問題界面: 這里寫圖片描述

這個是布局代碼:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/aliceblue" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="@dimen/dimen_dp_40" android:background="@color/white" android:gravity="center" android:text="Title" android:textSize="@dimen/dimen_sp_18"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/content" android:layout_width="match_parent" android:layout_height="300dp" android:background="@color/antiquewhite" android:gravity="center" android:text="Content" android:textSize="@dimen/dimen_sp_30"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/content" android:layout_marginTop="@dimen/dimen_dp_20" android:gravity="center" android:hint="EditText"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="@dimen/dimen_dp_20" android:layout_marginRight="@dimen/dimen_dp_20" android:text="Button"/> </RelativeLayout></LinearLayout>

使用ScrollView嵌套后并且去掉滑動條,在setContentView()之后添加

//ScrollView去除滑動條android:scrollbars="none"http://設置Activity的SoftInputMode屬性值為adjustResizegetWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

效果如下: 這里寫圖片描述 代碼如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/aliceblue" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="@dimen/dimen_dp_40" android:background="@color/white" android:gravity="center" android:text="Title" android:textSize="@dimen/dimen_sp_18"/> <ScrollView android:scrollbars="none" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/content" android:layout_width="match_parent" android:layout_height="300dp" android:background="@color/antiquewhite" android:gravity="center" android:text="Content" android:textSize="@dimen/dimen_sp_30"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/content" android:layout_marginTop="@dimen/dimen_dp_20" android:gravity="center" android:hint="EditText"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="@dimen/dimen_dp_20" android:layout_marginRight="@dimen/dimen_dp_20" android:text="Button"/> </RelativeLayout> </ScrollView></LinearLayout>

Activity代碼如下:

public class EditTextSqueezedTitle extends BaseActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edittext_squeezed_title); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); }}

雖然解決了問題但帶來了新的問題,ScrollView的特性影響了我的布局,后來找到方法,只需要在ScrollView屬性加上一句代碼:

android:fillViewport="true"

默認占滿屏幕,并且把ScrollView的唯一子布局RelativeLayout改為LinearLayout不然adjustResize屬性 不起作用或者是其他問題這是最終效果圖: 這里寫圖片描述

這是最終布局代碼:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/aliceblue" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="@dimen/dimen_dp_40" android:background="@color/white" android:gravity="center" android:text="Title" android:textSize="@dimen/dimen_sp_18"/> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="300dp" android:background="@color/antiquewhite" android:gravity="center" android:text="Content" android:textSize="@dimen/dimen_sp_30"/> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/dimen_dp_20" android:gravity="center" android:hint="EditText"/> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:layout_marginBottom="@dimen/dimen_dp_20" android:layout_marginRight="@dimen/dimen_dp_20" android:text="Button"/> </LinearLayout> </ScrollView></LinearLayout>

ScrollView嵌套LinearLayout這一步很重要,不然會引起其他問題,比如底部的Button依然會被軟鍵盤頂起


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 崇州市| 淄博市| 水富县| 基隆市| 阜新市| 黑河市| 双流县| 香河县| 祁东县| 收藏| 利辛县| 三门峡市| 银川市| 阜新市| 巩留县| 杭锦旗| 申扎县| 京山县| 绵竹市| 宜都市| 称多县| 秦皇岛市| 剑川县| 繁昌县| 镇平县| 翁牛特旗| 贡嘎县| 莎车县| 鄂伦春自治旗| 焦作市| 贵德县| 马尔康县| 雅江县| 武威市| 广元市| 通辽市| 宝山区| 淅川县| 清新县| 稷山县| 阳泉市|