美文网首页
Android软键盘弹起对布局的影响和解决方案

Android软键盘弹起对布局的影响和解决方案

作者: 微微心凉L | 来源:发表于2018-05-18 16:07 被阅读0次

    1.emmm 从头开始 ,先看看效果图 和 实际效果图 (这图片好大啊 第一次写不知道怎么调)


    QQ截图20180518154052.png 35109244.jpg
    1. 为了这个问题我也疯狂百度,问了很多人 ,但是就是没有效果, 后来加了一些代码就可以了。好了上代码。

    首先弹起的展示的代码,很简单的布局嵌套

    <LinearLayout
    
                android:id="@+id/news_list_lt"
                android:layout_width="match_parent"
                android:layout_height="@dimen/x96"
                android:background="#fcfcfc"
                android:orientation="horizontal">
    
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginLeft="@dimen/x26"
                    android:layout_marginRight="@dimen/x48"
                    android:layout_weight="1">
    
                    <EditText
                        android:id="@+id/business_content"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/x66"
                        android:layout_gravity="center"
                        android:background="@mipmap/img_edit_bg"
                        android:hint="输入聊天内容"
                        android:paddingLeft="@dimen/x6" />
    
                </RelativeLayout>
    
                <TextView
                    android:id="@+id/business_text_apply"
                    android:layout_width="@dimen/x117"
                    android:layout_height="@dimen/x58"
                    android:layout_gravity="center"
                    android:layout_marginRight="@dimen/x56"
                    android:background="@drawable/edit_apply_bg"
                    android:gravity="center"
                    android:text="发送"
                    android:textColor="#ffffff"
                    android:textSize="@dimen/x26" />
    
            </LinearLayout>
    
    

    在说说解决办法,

    1. 如下 ,在跟布局中加入了android:fitsSystemWindows 关于这个不做解释 ,欢迎大家自己
      百度加深印象

      android:fitsSystemWindows="true"
      android:focusable="true"
      
    2. 在清单文件中 主要设置了 android:windowSoftInputMode 关于adjustResize 意思是;这
      个属性表示Activity的主窗口总是会被调整大小,从而保证软键盘显示空间。

         <activity
              android:name=".xxxx.xxxx.BusinessDetailsActivity"
              android:windowSoftInputMode="adjustResize"></activity>
      

    基本上以上操作都没问题。在运行的时候就会发现神奇的事情,布局没错乱也正常把输入框顶上去了。

    以上针对个人解决方案。个人感觉基本差不多了,如果有什么不对欢迎大家指导。

    相关文章

      网友评论

          本文标题:Android软键盘弹起对布局的影响和解决方案

          本文链接:https://www.haomeiwen.com/subject/frbgdftx.html