当我在点击EditText时候,屏幕会整体上移,但是屏幕中有一个webview的布局,还在原来的位置,并且会遮挡布局。而且webview布局里的内容还消失了,怎么解决webview的遮挡问题,还有webview的显示问题?
public class MainActivity extends Activity {

private WebView webView;  
static final String mimeType = "text/html";  
static final String encoding = "utf-8";   @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
setContentView(R.layout.activity_main);
init();
} private void init() {
webView = (WebView) findViewById(R.id.social_list_feed_message_textview);
this.localHtmlZh();
// webViewFeed.setTextDirection(textDirection);
} private void localHtmlZh() {
try {  
      String data = "<html>在模拟器 2.1 上测试</html>";  
      // utf-8编码处理(在SDK1.5模拟器和真实设备上都将出现乱码,SDK1.6上能正常显示)  
      // MyWebView.loadData(data, mimeType, encoding);  
      // 对数据进行编码处理(SDK1.5版本)  
      webView.loadData(URLEncoder.encode(data, encoding), mimeType, encoding);  
      // MyWebView.loadDataWithBaseURL(null, data, mimeType, encoding, null);  
  
    } catch (Exception ex) {  
      ex.printStackTrace();  
    } 
}

public boolean onTouchEvent(MotionEvent event) {
        if(null != this.getCurrentFocus()){
            /**
             * 点击空白位置 隐藏软键盘
             */
            InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            return mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
        }
        return super .onTouchEvent(event);
    }
}

解决方案 »

  1.   

    用RelativeLayout布局
      

  2.   

    把这些东西都放到scrollview中
      

  3.   

    在AndroidManifest.xml该布局的activity加上android:windowSoftInputMode="adjustResize|stateHidden"
      

  4.   

    把 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);  去掉xml改成<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.edittext.zedittext.MainActivity"
        android:orientation="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="hi" />
           <ImageView
               android:layout_width="match_parent"
               android:layout_height="200dp"
               android:src="@drawable/hb_down"
               />       <WebView
               android:id="@+id/social_list_feed_message_textview"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_marginRight="10dip"
               android:layout_marginTop="5dip"
               />       <ImageView
               android:layout_width="match_parent"
               android:layout_height="200dp"
               android:src="@drawable/hb_down"
               />       <LinearLayout
               android:layout_width="match_parent"
               android:layout_height="50dp"
               android:orientation="horizontal"
               android:gravity="center_vertical"
               >           <EditText
                   android:layout_width="0dp"
                   android:layout_height="50dp"
                   android:hint="请输入信息"
                   android:layout_weight="4"
                   />
               <Button
                   android:layout_width="0dp"
                   android:layout_weight="1"
                   android:layout_height="wrap_content"
                   android:text="post"
                   ></Button>
           </LinearLayout>
       </LinearLayout></ScrollView>就可以了
      

  5.   

    软键盘挡住WebView中输入框解决方法https://blog.csdn.net/lin_dianwei/article/details/80501339