本文參考:
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);效果如下:
代碼如下:
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依然會被軟鍵盤頂起
新聞熱點
疑難解答