一.android:windowSoftInputMode屬性詳解
【1】stateUnspecified:軟鍵盤的狀態並沒有指定,系統將選擇一個合適的狀態或依賴於主題的設置
【2】stateUnchanged:當這個activity出現時,軟鍵盤將一直保持在上一個activity裏的狀態,無論是隱藏還是顯示
【3】stateHidden:用戶選擇activity時,軟鍵盤總是被隱藏
【4】stateAlwaysHidden:當該Activity主窗口獲取焦點時,軟鍵盤也總是被隱藏的
【5】stateVisible:軟鍵盤通常是可見的
【6】stateAlwaysVisible:用戶選擇activity時,軟鍵盤總是顯示的狀態
【7】adjustUnspecified:默認設置,通常由系統自行決定是隱藏還是顯示
【8】adjustResize:該Activity總是調整屏幕的大小以便留出軟鍵盤的空間
【9】adjustPan:當前窗口的內容將自動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內容的部分
二.EditText的使用
需求:模仿ios的輸入框效果,在鍵盤彈出來輸入的時候,佈局除去標題欄整體向上滑動
如果用ScrollView將中間的佈局包裹,而底部的提交評價的view設置layout_alignParentBottom爲ture,最後會被軟鍵盤頂上來
最後只有將底部的view放在ScrollView包裹的LinearLayout裏面,值得注意是:
- 1.ScrollView只能包裹一個子佈局
- 2.當ScrollView的子佈局想填滿ScrollView時,使用”match_parent”是不管用的,必需爲ScrollView設置:android:fillViewport=”true”。
然後將面試評價的佈局設置成自增長就行了,這樣底部的提交評價view就可以顯示在屏幕最底部了
佈局代碼:
- manifest:
<activity
android:name=".view.activity.InterviewAssessActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden" />
- layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.recruit.cymobi.view.activity.InterviewAssessActivity">
<com.recruit.cymobi.view.widget.TitleBarView
android:id="@+id/titleBar"
style="@style/TitleBarDefault"
app:TitleBar_center_text="@string/interview_assess_title"
app:TitleBar_left_Drawable="@drawable/icon_back" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/titleBar"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/interview_assess"
android:textColor="@color/c_333333"
android:textSize="16sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="10dp"
android:background="@drawable/bg_edit_resume"
android:gravity="top"
android:hint="@string/interview_assess_des"
android:padding="10dp"
android:textColorHint="#bcbcbc"
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_comit_assess"
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="@color/white"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:drawableLeft="@drawable/icon_anonymous_no"
android:gravity="center"
android:padding="13dp"
android:text="@string/anonymous"
android:textColor="@color/c_333333"
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape_button_finish"
android:gravity="center"
android:text="@string/commit_assess"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>