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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

EditText彈出軟鍵盤(pán)后布局上移問(wèn)題

2019-11-09 15:49:11
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文參考:

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

解決其文章的后續(xù)其他問(wèn)題: 這個(gè)是問(wèn)題界面: 這里寫(xiě)圖片描述

這個(gè)是布局代碼:

<?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嵌套后并且去掉滑動(dòng)條,在setContentView()之后添加

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

效果如下: 這里寫(xiě)圖片描述 代碼如下:

<?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); }}

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

android:fillViewport="true"

默認(rèn)占滿屏幕,并且把ScrollView的唯一子布局RelativeLayout改為L(zhǎng)inearLayout不然adjustResize屬性 不起作用或者是其他問(wèn)題這是最終效果圖: 這里寫(xiě)圖片描述

這是最終布局代碼:

<?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這一步很重要,不然會(huì)引起其他問(wèn)題,比如底部的Button依然會(huì)被軟鍵盤(pán)頂起


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 囊谦县| 新宾| 蓝田县| 泽州县| 赤水市| 汉沽区| 惠东县| 建水县| 阿拉善盟| 平江县| 三原县| 容城县| 大方县| 牡丹江市| 云安县| 江安县| 丰都县| 通海县| 宣恩县| 乐陵市| 清苑县| 南康市| 侯马市| 桐柏县| 日喀则市| 峨眉山市| 息烽县| 淮阳县| 沙雅县| 宁都县| 牟定县| 界首市| 南通市| 拉萨市| 高要市| 杂多县| 咸阳市| 奈曼旗| 忻城县| 龙岩市| 高州市|