zoukankan      html  css  js  c++  java
  • 解决位于底端Edittext 输入时被软盘遮盖

    1. 遇到这种情况我们首先到网上搜一圈,大概情况是需要设置<activity/> 

      android:windowSoftInputMode="adjustResize" ,按照以上属性设置了,问题依然存在没有解决。

    2. 通过反复试验,得出结论布局文件的layout_weight权重为影响软盘覆盖edittext。成功的xml文件如下:
    3. <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#f4f6f5"
          android:orientation="vertical" >
      
          <!-- head bar -->
          <include layout="@layout/include_head_bar" />
      
          <ListView
              android:id="@+id/listview"
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1" 
              android:layout_marginLeft="10.0dip"
              android:layout_marginRight="10.0dip"
              android:layout_marginTop="10.0dip"
              android:cacheColorHint="#00000000"
              android:divider="@null"
              android:dividerHeight="5dp"
              android:scrollbars="none" />
      
          <LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="5" >
      
              <RelativeLayout
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="5dp" >
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_alignParentBottom="true"
                      android:background="#f5f5f5" >
      
                      <ImageButton
                          android:id="@+id/btnVoice"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:background="#00000000"
                          android:paddingLeft="5dp"
                          android:src="@drawable/voice" />
      
                      <EditText
                          android:id="@+id/txtContent"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_gravity="left"
                          android:layout_marginLeft="5dp"
                          android:layout_weight="1"
                          android:background="@drawable/shape_consult_search"
                          android:completionThreshold="1"
                          android:hint="输入内容"
                          android:paddingLeft="8dp"
                          android:textColor="#000000"
                          android:textColorHint="#c2c2c2"
                          android:textCursorDrawable="@null" />
      
                      <ImageButton
                          android:id="@+id/btnPic"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_marginLeft="5dp"
                          android:background="#00000000"
                          android:src="@drawable/pic" />
      
                      <Button
                          android:id="@+id/btnConsult"
                          android:layout_width="wrap_content"
                          android:layout_height="40dp"
                          android:layout_marginLeft="5dp"
                          android:layout_marginRight="5dp"
                          android:background="@drawable/shape_consult_top_btn_press"
                          android:text="发送"
                          android:textColor="#ffffff" />
                  </LinearLayout>
              </RelativeLayout>
          </LinearLayout>
      
      </LinearLayout>

      效果图:

    4. 经过反复测试,还得出另一解决方案。需要将权重比较大的组件放到相对布局文件中,请看xml布局文件
    5. <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="match_parent"
          android:background="#e9e9e9"
          android:focusable="true"
          android:focusableInTouchMode="true"
          android:orientation="vertical" >
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:background="#f0f0f0"
              android:gravity="center_vertical" >
      
              <TextView
                  android:id="@+id/return_back"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:drawableLeft="@drawable/return_back"
                  android:gravity="center|center_vertical"
                  android:paddingLeft="15dp"
                  android:text="@string/return_back"
                  android:textColor="#20bf63"
                  android:textSize="22sp" />
      
              <TextView
                  android:layout_width="0dip"
                  android:layout_height="match_parent"
                  android:layout_weight="2"
                  android:gravity="center|center_vertical"
                  android:text="@string/zx_tit"
                  android:textColor="#000000"
                  android:textSize="22sp" />
      
              <TextView
                  android:layout_width="40dp"
                  android:layout_height="match_parent"
                  android:gravity="center_vertical"
                  android:singleLine="true" />
          </LinearLayout>
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="#ffffff"
              android:orientation="vertical"
              android:paddingBottom="15dp"
              android:paddingLeft="15dp"
              android:paddingRight="15dp"
              android:paddingTop="10dp" >
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" >
      
                  <TextView
                      android:layout_width="wrap_content"
                      android:layout_height="match_parent"
                      android:layout_alignParentLeft="true"
                      android:layout_gravity="left"
                      android:layout_weight="1"
                      android:text="@string/zx_name"
                      android:textColor="#8b8b8b"
                      android:textSize="18sp" />
      
                  <TextView
                      android:layout_width="wrap_content"
                      android:layout_height="match_parent"
                      android:layout_alignParentRight="true"
                      android:layout_gravity="right"
                      android:layout_weight="1"
                      android:gravity="right"
                      android:text="@string/zx_time"
                      android:textColor="#8b8b8b"
                      android:textSize="18sp" />
              </LinearLayout>
      
              <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:singleLine="true"
                  android:text="@string/zx_text"
                  android:textColor="#000000"
                  android:textSize="18sp" />
          </LinearLayout>
      
          <LinearLayout
              android:layout_width="fill_parent"
              android:layout_height="match_parent"
              android:layout_weight="1" >
      
              <RelativeLayout
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content" >
      
                  <ListView
                      android:id="@+id/listview"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginLeft="10.0dip"
                      android:layout_marginRight="10.0dip"
                      android:layout_marginTop="10.0dip"
                      android:cacheColorHint="#00000000"
                      android:divider="@null"
                      android:dividerHeight="5dp" />
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_alignParentBottom="true"
                      android:background="#f5f5f5" >
      
                      <EditText
                          android:id="@+id/txtContent"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_gravity="left"
                          android:layout_marginLeft="5dp"
                          android:layout_weight="1"
                          android:background="@drawable/shape_consult_search"
                          android:completionThreshold="1"
                          android:hint="输入内容"
                          android:paddingLeft="8dp"
                          android:textColor="#000000"
                          android:textColorHint="#c2c2c2"
                          android:textCursorDrawable="@null" />
      
                      <Button
                          android:id="@+id/btnConsult"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_marginLeft="5dp"
                          android:layout_marginRight="5dp"
                          android:background="@drawable/shape_consult_top_btn_press"
                          android:text="发送"
                          android:textColor="#ffffff" />
                  </LinearLayout>
              </RelativeLayout>
          </LinearLayout>
      
      </LinearLayout>

      我们首先分析下这个布局文件:由三个linearlayout组成,其中前两个layout的高度肯定可以确定其高度,第三个layout比较复杂,包含一个 listView  relativelayout ,listview

    6. 中的内容是动态的,也就是说高度不定,内容不定;而且还有下边[发送]必须在屏幕的底端显示;假如我们把listview提到独立的layout中,当我们点击edittext输入内容时,就会被
    7. 软盘挡住。
    8. 另还需注意,具体问题具体分析。
  • 相关阅读:
    Python装饰器的解包装(unwrap)
    《Python cookbook》 “定义一个属性可由用户修改的装饰器” 笔记
    关于Python的函数(Method)与方法(Function)
    判断python对象是否可调用的三种方式及其区别
    tornado返回指定的http code
    Mac下安装pymssql
    iptables
    OpenFlow通信流程解读
    Prometheus的架构及持久化
    ansible总结
  • 原文地址:https://www.cnblogs.com/gaolizhong/p/4380848.html
Copyright © 2011-2022 走看看