最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)鍵盤彈出界面上移的實現(xiàn)思路

 更新時間:2018年04月12日 09:51:53   作者:mayundoyouknow  
這篇文章主要介紹了Android實現(xiàn)鍵盤彈出界面上移的實現(xiàn)思路,需要的朋友可以參考下

1.首先說一下思路:

基本就是結(jié)合layout中ScrollView視圖和AndroidManifest.xml中activity中的android:windowSoftInputMode屬性配置實現(xiàn);

2.要了解android:windowSoftInputMode相應(yīng)的可以配置項:

activity主窗口與軟鍵盤的交互模式,可以用來避免輸入法面板遮擋問題,Android1.5后的一個新特性。
這個屬性能影響兩件事情:

 1.當有焦點產(chǎn)生時,軟鍵盤是隱藏還是顯示

 2.是否減少活動主窗口大小以便騰出空間放軟鍵盤
windowSoftInputMode的設(shè)置必須是下面列表中的一個值,或一個”state…”值加一個”adjust…”值的組合。在任一組設(shè)置多個值——多個”state…”values,例如&mdash有未定義的結(jié)果。各個值之間用|分開。

例如:<activity android:windowSoftInputMode="stateVisible|adjustResize". . . >

在這設(shè)置的值(除"stateUnspecified"和"adjustUnspecified"以外)將覆蓋在主題中設(shè)置的值
各值的含義:

stateUnspecified:軟鍵盤的狀態(tài)并沒有指定,系統(tǒng)將選擇一個合適的狀態(tài)或依賴于主題的設(shè)置

stateUnchanged:當這個activity出現(xiàn)時,軟鍵盤將一直保持在上一個activity里的狀態(tài),無論是隱藏還是顯示

stateHidden:用戶選擇activity時,軟鍵盤總是被隱藏

stateAlwaysHidden:當該Activity主窗口獲取焦點時,軟鍵盤也總是被隱藏的

stateVisible:軟鍵盤通常是可見的

stateAlwaysVisible:用戶選擇activity時,軟鍵盤總是顯示的狀態(tài)

adjustUnspecified:默認設(shè)置,通常由系統(tǒng)自行決定是隱藏還是顯示

adjustResize:該Activity總是調(diào)整屏幕的大小以便留出軟鍵盤的空間

adjustPan:當前窗口的內(nèi)容將自動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內(nèi)容的部分

例如:

AndroidManifest.xml文件中界面對應(yīng)的<activity>里加入
android:windowSoftInputMode="adjustPan"   鍵盤就會覆蓋屏幕
android:windowSoftInputMode="stateVisible|adjustResize"   屏幕整體上移(結(jié)合ScrollView實現(xiàn))
android:windowSoftInputMode="adjustPan|stateHidden" 軟鍵盤彈出,界面布局不變,這是解決彈出軟鍵盤,界面整體被壓縮的方式(會導(dǎo)致整個界面上移動,顯示效果不好)

3.具體實現(xiàn)

3.1定義ScrollView

<ScrollView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:fitsSystemWindows="true"
  android:scrollbars="vertical">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/set_account_info"
      android:layout_marginTop="@dimen/business_management_title_top"
      style="@style/large_size_home_main_color_style"
      android:layout_gravity="center_horizontal"/>
    <RelativeLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:layout_marginTop="@dimen/add_confirm_top"
      android:focusable="true"
      android:focusableInTouchMode="true">
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/add_accout_bank_title"
        style="@style/cheque_collection_hint"
        android:layout_alignBaseline="@+id/accout_bank"
        android:text="@string/accout_bank"/>
      <EditText
        android:layout_width="@dimen/add_account_code_w"
        android:layout_marginTop="@dimen/common_gap"
        android:layout_toRightOf="@+id/add_accout_bank_title"
        style="@style/cheque_collection_et"
        android:id="@+id/accout_bank"/>
    </RelativeLayout>
    <Button
      android:id="@+id/confirm_add_btn"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      style="@style/common_btn_style"
      android:layout_gravity="center_horizontal"
      android:layout_marginTop="@dimen/add_confirm_top"
      android:text="@string/confirmed" />
  </LinearLayout>
</ScrollView>

即ScrollVIew中包裹EditText等內(nèi)容;

3.2為AndroidManifest.xml文件中activity添加android:windowSoftInputMode="stateHidden|adjustResize"屬性

<activity
  android:name=".ui.AddAccountActivity" android:windowSoftInputMode="stateHidden|adjustResize"
  android:screenOrientation="landscape"/>

說明:

stateHidden:進入Activity默認隱藏鍵盤,通常需要看見整個頁面,用戶需要輸入時點擊輸入框;

adjustResize:界面調(diào)整大小,鍵盤留在底部,ScrollView內(nèi)容可以滾動,這樣就繼續(xù)可以看到整個頁面;

ScrollView通常不要設(shè)置android:fillViewport="true"(作用就是布滿整個屏幕即使內(nèi)容高度沒有屏幕的高度)屬性(看實際需要吧),android:fillViewport="true"導(dǎo)致界面無法滾動,API 19,21有這個問題,API 27沒有這個問題,主要看你適配的版本和需求了;

3.3效果圖如下

總結(jié)

以上所述是小編給大家介紹的Android實現(xiàn)鍵盤彈出界面上移,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

沙雅县| 两当县| 朝阳县| 闽侯县| 白水县| 韶关市| 白朗县| 禹州市| 长宁区| 浮山县| 青阳县| 克拉玛依市| 那曲县| 崇义县| 呼伦贝尔市| 广元市| 稷山县| 武穴市| 永寿县| 台北市| 周口市| 凤山县| 桦南县| 蚌埠市| 邵东县| 嘉荫县| 灵丘县| 淳安县| 铜鼓县| 偃师市| 葫芦岛市| 河津市| 保定市| 绥江县| 长沙市| 达尔| 平度市| 内丘县| 福州市| 盘山县| 嵊泗县|