pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

單擊時(shí)鍵盤重疊 EditText

Keyboard overlapping EditText on click(單擊時(shí)鍵盤重疊 EditText)
本文介紹了單擊時(shí)鍵盤重疊 EditText的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

在我的片段中,我在滾動(dòng)視圖中有一個(gè) editText,當(dāng)我點(diǎn)擊它時(shí),我將它設(shè)置為像這樣打開:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

從第一次打開它就可以正常工作,但是當(dāng)我關(guān)閉鍵盤并再次打開它時(shí),它與editText重疊,如何將editText設(shè)置為始終以SOFT_INPUT_ADJUST_PAN模式打開?

XML:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:custom="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/雪花石膏"><文本視圖android:id="@+id/semconexao"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="驗(yàn)證 sua conex?o com a internet"機(jī)器人:重力=中心"android:layout_marginTop="10dp"android:visibility="消失"/><滾動(dòng)視圖android:id="@+id/scroll"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_above="@+id/footer"><線性布局android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="垂直"><相對(duì)布局android:layout_width="fill_parent"android:layout_height="wrap_content"android:visibility="可見"><com.android.volley.toolbox.NetworkImageViewandroid:id="@+id/imageInst"android:layout_width="match_parent"android:layout_height="200dp"android:scaleType="centerCrop"安卓:可見性=可見"/><com.retornar.utils.CircledNetworkImageViewandroid:id="@+id/縮略圖"android:layout_width="@dimen/logo_maior"android:layout_height="@dimen/logo_maior"android:layout_marginLeft="20dp"android:layout_marginTop="100dp"機(jī)器人:adjustViewBounds =真"android:scaleType="centerCrop"></com.retornar.utils.CircledNetworkImageView><圖像視圖android:id="@+id/更多"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/ic_amp"機(jī)器人:可見性=消失"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_alignParentEnd="true"/></相對(duì)布局><文本視圖android:id="@+id/retornarTitulo"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_below="@+id/imageInst"android:layout_marginTop="20dp"機(jī)器人:重力=中心"安卓:填充=10dp"android:text="@string/retornarTitulo"android:textColor="@color/犰狳"android:textSize="@dimen/text2"/><文本視圖android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_below="@+id/retornarTitulo"機(jī)器人:重力=中心"安卓:填充=10dp"android:text="@string/retornar"android:textColor="@color/犰狳"android:textSize="@dimen/text1"/><包括 layout="@layout/valores"/><編輯文本android:id="@+id/campovalor"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="60dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="10dp"android:background="@drawable/shadowedittext"機(jī)器人:重力=中心"android:hint="ou entre com um valor"android:imeOptions="actionDone"android:inputType="numberDecimal"安卓:填充=10dp"android:singleLine="true"/><查看android:layout_width="match_parent"android:layout_height="1dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="20dp"android:background="@color/gray"/><文本視圖android:id="@+id/propText"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="30dp"android:layout_marginTop="20dp"機(jī)器人:重力=中心"安卓:填充=10dp"android:text="Propósito em destaque"android:textColor="@color/犰狳"android:textSize="@dimen/text2"安卓:可見性=消失"/><包括布局=@layout/inst_prop"/><圖像視圖android:id="@+id/maisprop"android:layout_width="wrap_content"android:layout_height="wrap_content"安卓:layout_gravity="center"android:layout_marginTop="20dp"android:src="@drawable/ic_proposito"安卓:可見性=消失"/><文本視圖android:id="@+id/maisproptext"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="80dp"android:layout_marginTop="10dp"機(jī)器人:重力=中心"android:text="Mais propósitos"android:textColor="@color/犰狳"安卓:可見性=消失"/></線性布局></滾動(dòng)視圖><文本視圖android:id="@+id/ret"fontPath="字體/Avenir-Bold.ttf"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"安卓:阿爾法=0.9"android:background="@color/blumine"機(jī)器人:重力=中心"安卓:填充=15dp"安卓:文本=DOAR"android:textColor="@color/white"/></相對(duì)布局>

解決方案

設(shè)置 RESIZE 而不是 PAN 怎么樣?您將能夠?qū)?EditText 保持在 SoftKeyboard 之上.嘗試如下:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

但是,您可以在 manifest 中將其設(shè)置為 Activity (parent) 屬性,而不是在運(yùn)行時(shí)執(zhí)行此操作.這也將在您的片段 (child) 中處理:

為了防止這種行為,只需將 ScrollView 設(shè)置在最后一個(gè) TextView 上方,如下所示:

你會(huì)得到以下結(jié)果:

In my fragment I have an editText inside a scrollview and when I click on that I set it to open like this:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

It works fine from the first time it opens, but when I close the keyboard and open it again, it overlaps the editText, how can I set the editText to always open in SOFT_INPUT_ADJUST_PAN mode?

the XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/alabaster">

    <TextView
        android:id="@+id/semconexao"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Verifique sua conex?o com a internet"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:visibility="gone"/>


    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/footer">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:visibility="visible">



                <com.android.volley.toolbox.NetworkImageView
                    android:id="@+id/imageInst"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:scaleType="centerCrop"
                    android:visibility="visible" />

                <com.retornar.utils.CircledNetworkImageView
                    android:id="@+id/thumbnail"
                    android:layout_width="@dimen/logo_maior"
                    android:layout_height="@dimen/logo_maior"
                    android:layout_marginLeft="20dp"
                    android:layout_marginTop="100dp"
                    android:adjustViewBounds="true"
                    android:scaleType="centerCrop">

                </com.retornar.utils.CircledNetworkImageView>

                <ImageView
                    android:id="@+id/more"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_amp"
                    android:visibility="gone"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true" />

            </RelativeLayout>


            <TextView
                android:id="@+id/retornarTitulo"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/imageInst"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/retornarTitulo"
                android:textColor="@color/armadillo"
                android:textSize="@dimen/text2" />


            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/retornarTitulo"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/retornar"
                android:textColor="@color/armadillo"
                android:textSize="@dimen/text1" />

            <include layout="@layout/valores" />


            <EditText
                android:id="@+id/campovalor"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="60dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/shadoweditext"
                android:gravity="center"
                android:hint="ou entre com um valor"
                android:imeOptions="actionDone"
                android:inputType="numberDecimal"
                android:padding="10dp"
                android:singleLine="true" />


            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="20dp"
                android:background="@color/gray" />

            <TextView
                android:id="@+id/propText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="30dp"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:padding="10dp"
                android:text="Propósito em destaque"
                android:textColor="@color/armadillo"
                android:textSize="@dimen/text2"
                android:visibility="gone" />

            <include layout="@layout/inst_prop" />

            <ImageView
                android:id="@+id/maisprop"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:src="@drawable/ic_proposito"
                android:visibility="gone" />

            <TextView
                android:id="@+id/maisproptext"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="80dp"
                android:layout_marginTop="10dp"
                android:gravity="center"
                android:text="Mais propósitos"
                android:textColor="@color/armadillo"
                android:visibility="gone" />

        </LinearLayout>
    </ScrollView>

    <TextView
        android:id="@+id/ret"
        fontPath="fonts/Avenir-Bold.ttf"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:alpha="0.9"
        android:background="@color/blumine"
        android:gravity="center"
        android:padding="15dp"
        android:text="DOAR"
        android:textColor="@color/white" />

</RelativeLayout>

解決方案

What about setting RESIZE instead of PAN? You will be able to keep your EditText above the SoftKeyboard. Try as follows:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

However, instead of doing this at runtime, you can set it in the manifest as an Activity (parent) attribute. This will also be handled in your fragment (child):

<activity
    android:name=".NameActivity"
    android:label="@string/app_name"
    android:windowSoftInputMode="stateAlwaysHidden|adjustResize">

Then, as you can see, the EditText is above the SoftKeyboard, but from your layout, you have a TextView with android:layout_alignParentBottom="true" attribute which will overlap the EditText:

To prevent this behaviour, just set the ScrollView above the last TextView as follows:

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/ret"> <!-- instead of "footer" -->

And you will get the following result:

這篇關(guān)于單擊時(shí)鍵盤重疊 EditText的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 上海质量认证办理中心 | 点胶机_点胶阀_自动点胶机_智能点胶机_喷胶机_点胶机厂家【欧力克斯】 | 网优资讯-为循环资源、大宗商品、工业服务提供资讯与行情分析的数据服务平台 | 密封无忧网 _ 专业的密封产品行业信息网 | 银川美容培训-美睫美甲培训-彩妆纹绣培训-新娘化妆-学化妆-宁夏倍莱妮职业技能培训学校有限公司 临时厕所租赁_玻璃钢厕所租赁_蹲式|坐式厕所出租-北京慧海通 | 黄石妇科医院_黄石东方女子医院_黄石东方妇产医院怎么样 | 低压载波电能表-单相导轨式电能表-华邦电力科技股份有限公司-智能物联网综合管理平台 | 珠宝展柜-玻璃精品展柜-首饰珠宝展示柜定制-鸿钛展柜厂家 | 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | 手机游戏_热门软件app下载_好玩的安卓游戏下载基地-吾爱下载站 | 郑州墨香品牌设计公司|品牌全案VI设计公司 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 选矿设备-新型重选设备-金属矿尾矿重选-青州冠诚重工机械有限公司 | 礼堂椅厂家|佛山市艺典家具有限公司 | 日本细胞免疫疗法_肿瘤免疫治疗_NK细胞疗法 - 免疫密码 | 密集柜_档案密集柜_智能密集架_密集柜厂家_密集架价格-智英伟业 密集架-密集柜厂家-智能档案密集架-自动选层柜订做-河北风顺金属制品有限公司 | 东莞市天进机械有限公司-钉箱机-粘箱机-糊箱机-打钉机认准东莞天进机械-厂家直供更放心! | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 高楼航空障碍灯厂家哪家好_航空障碍灯厂家_广州北斗星障碍灯有限公司 | 渣土车电机,太阳能跟踪器电机,蜗轮蜗杆减速电机厂家-淄博传强电机 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 | 拉伸膜,PE缠绕膜,打包带,封箱胶带,包装膜厂家-东莞宏展包装 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 锂离子电池厂家-山东中信迪生电源| 政府园区专业委托招商平台_助力企业选址项目快速落地_东方龙商务集团 | pbootcms网站模板|织梦模板|网站源码|jquery建站特效-html5模板网 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 | 东莞市踏板石餐饮管理有限公司_正宗桂林米粉_正宗桂林米粉加盟_桂林米粉加盟费-东莞市棒子桂林米粉 | 合肥仿石砖_合肥pc砖厂家_合肥PC仿石砖_安徽旭坤建材有限公司 | 耐破强度测试仪-纸箱破裂强度试验机-济南三泉中石单品站 | 台式低速离心机-脱泡离心机-菌种摇床-常州市万丰仪器制造有限公司 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 超声波清洗机_大型超声波清洗机_工业超声波清洗设备-洁盟清洗设备 | 水性漆|墙面漆|木器家具漆|水漆涂料_晨阳水漆官网 | 耐热钢-耐磨钢-山东聚金合金钢铸造有限公司 |