ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

android:windowSoftInputMode =“ adjustResize”无法正常运行

2019-11-22 01:24:11  阅读:282  来源: 互联网

标签:android-layout relativelayout window-soft-input-mode xml android


即使此问题在stackoverflow中有很多解决方案,我也无法解决.
我在屏幕上有两个编辑文本,一个在顶部,另一个在屏幕底部.
每当我单击底部的编辑文本时,软键面板就会显示在上方.我已经玩过windowSoftInputMode.

当我单击底部的edittext时,我不希望屏幕的其他内容向上滚动.

这是我的xml布局.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
>
<RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >
<EditText
   android:id="@+id/phone_number_edit_text_compose"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   android:layout_alignParentTop="true"
   android:layout_marginLeft="@dimen/activity_horizontal_margin"
   android:layout_marginTop="@dimen/activity_horizontal_margin"
   android:layout_toLeftOf="@id/select_contact"
   android:background="@drawable/phone_edittext_background_selector"
   android:ems="10"
   android:hint="@string/phone_edittext_hint"
   android:inputType="phone"
   android:paddingBottom="12dp"
   android:paddingLeft="8dp"
   android:paddingTop="12dp"
   android:textAppearance="?android:attr/textAppearanceMedium"
   android:textColor="@color/white" />

<ImageButton
 android:id="@+id/selectcontact_compose"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_alignBottom="@+id/phone_number_edit_text_compose"
 android:layout_marginTop="@dimen/activity_horizontal_margin"
 android:layout_toRightOf="@id/phone_number_edit_text_compose"
 android:background="@drawable/select_contact_background_selector"
 android:contentDescription="@string/select_contact_content_description"
 android:src="@drawable/select_contact_selector"
 android:layout_marginLeft="2dp" 
 android:paddingLeft="8dp"
 android:paddingRight="8dp"/>

<View
     android:id="@+id/view1"
     android:layout_width="wrap_content"
     android:layout_height="2px"
     android:layout_below="@id/phone_number_edit_text_compose"
     android:layout_marginTop="@dimen/redial_screen_distance_between_views"
     android:background="@drawable/separator" />

<LinearLayout
   android:id="@+id/repetition_layout"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_below="@+id/view1"
   android:clickable="true"
   android:onClick="RepetitionLayoutClickListener"
   android:orientation="horizontal"
   android:paddingBottom="@dimen/redial_screen_distance_between_views"
   android:paddingTop="@dimen/redial_screen_distance_between_views" 
   android:background="@drawable/repetition_layout_background_selector"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin">

<TextView
  android:id="@+id/repetition_textview"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/repetition"
  android:textColor="@color/green"
  android:textAppearance="?android:attr/textAppearanceLarge" />

<Spinner
  android:id="@+id/repetition_spinner"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@null"
  android:clickable="false"
  android:popupBackground="@color/dark_background" />

</LinearLayout>

<View
     android:id="@+id/view2"
     android:layout_width="wrap_content"
     android:layout_height="2px"
     android:layout_below="@id/repetition_layout"
     android:background="@drawable/separator" />

<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_below="@+id/view2"
   android:orientation="horizontal"
   android:paddingBottom="@dimen/redial_screen_distance_between_views"
   android:paddingTop="@dimen/redial_screen_distance_between_views" 
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:id="@+id/date_layout">

<TextView
   android:id="@+id/textView1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/d"
   android:textColor="@color/green"
   android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
   android:id="@+id/date_textview"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/a"
   android:paddingLeft="5dp"
   android:textColor="@color/white"
   android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<View
     android:id="@+id/view3"
     android:layout_width="wrap_content"
     android:layout_height="2px"
     android:layout_below="@id/date_layout"
     android:background="@drawable/separator" />

<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_below="@+id/view3"
   android:orientation="horizontal"
   android:paddingBottom="@dimen/redial_screen_distance_between_views"
   android:paddingTop="@dimen/redial_screen_distance_between_views" 
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:id="@+id/time_layout">

<TextView
   android:id="@+id/textView2"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/t"
   android:textColor="@color/green"
   android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
   android:id="@+id/time_textview"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="@string/b"
   android:paddingLeft="5dp"
   android:textColor="@color/white"
   android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</RelativeLayout>

<RelativeLayout
   android:id="@+id/compose_layout"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_weight="1">

<EditText
   android:id="@+id/editText1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/compose_message_background"
   android:hint="@string/compose_message_hint"
   android:paddingLeft="5dp"
   android:paddingRight="5dp"
   android:paddingTop="12dp"
   android:paddingBottom="12dp"
   android:layout_alignParentLeft="true"
   android:layout_alignParentBottom="true"
   android:textAppearance="?android:attr/textAppearanceMedium"
   android:layout_toLeftOf="@+id/imageButton1" >

</EditText>

<ImageButton
   android:id="@+id/imageButton1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/send_button_background"
   android:src="@drawable/ic_action_send_now" 
   android:paddingRight="8dp"
   android:paddingLeft="8dp"
   android:layout_alignBottom="@+id/editText1"
   android:layout_alignTop="@+id/editText1"
   android:layout_alignParentRight="true"/>
</RelativeLayout>

</LinearLayout>

这是我的清单XML.

    <activity
        android:name="com.task.SmsScreen"
        android:label="@string/app_name" 
        android:windowSoftInputMode="adjustResize"
      >        
    </activity>

解决方法:

删除外部的线性布局,并将所有内容放置在相对布局中.并通过将alignParentBottom设置为true,将底部编辑文本与布局的底部对齐.
最主要的是“不要对android:windowSoftInputMode做任何事情.”从清单文件中删除该行.
让android默认.

标签:android-layout,relativelayout,window-soft-input-mode,xml,android
来源: https://codeday.me/bug/20191122/2056137.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有