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

首頁 > 系統(tǒng) > Android > 正文

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

2019-10-22 18:12:58
字體:
供稿:網(wǎng)友

1.首先說一下思路:

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

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

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

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

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

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

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

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

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

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

stateAlwaysHidden:當(dāng)該Activity主窗口獲取焦點(diǎn)時(shí),軟鍵盤也總是被隱藏的

stateVisible:軟鍵盤通常是可見的

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

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

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

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

例如:

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

3.具體實(shí)現(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:進(jìn)入Activity默認(rèn)隱藏鍵盤,通常需要看見整個(gè)頁面,用戶需要輸入時(shí)點(diǎn)擊輸入框;

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

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

3.3效果圖如下

android,鍵盤彈出,界面上移

總結(jié)

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


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洱源县| 邯郸市| 石家庄市| 陈巴尔虎旗| 镇原县| 长治县| 达州市| 平罗县| 台中市| 华安县| 鄂温| 马关县| 锡林郭勒盟| 滦平县| 阳城县| 股票| 边坝县| 资溪县| 梧州市| 大渡口区| 友谊县| 沛县| 江阴市| 杨浦区| 资兴市| 定远县| 义马市| 秭归县| 扎囊县| 宁都县| 和林格尔县| 济源市| 莱州市| 葵青区| 鹤庆县| 阿坝县| 中卫市| 通山县| 夹江县| 河源市| 安图县|