当键盘弹出时向上移动布局

问题描述:

所以我有一个EditText在用户输入屏幕的底部,当我点击它时,键盘弹出并且它将其移动,但问题在于它如何移动。 EditText不是用键盘移动,而是键盘会显示,半秒钟后,EditText会卡入到位。当我关闭键盘时,EditText在返回到原始大小之前保持半秒的扩展大小。当键盘弹出时向上移动布局

问题是,是否可以平滑过渡?

不确定这是否会影响结果,但它在Fragment之内。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:backgroundTint="#c1c1c1"> 

    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/ListViewChat" 
     android:layout_alignParentLeft="false" 
     android:layout_alignParentStart="false" 
     android:dividerHeight="1dp" 
     android:layout_alignParentRight="false" 
     android:layout_alignParentEnd="false" 
     android:layout_below="@+id/tabs" 
     android:layout_above="@+id/relativeLayout4" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     android:id="@+id/relativeLayout4" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/editTextMessage" 
      android:hint="Enter a message..." 
      android:background="@android:color/transparent" 
      android:layout_alignBottom="@+id/buttonSend" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentTop="true" 
      android:layout_toLeftOf="@+id/buttonSend" 
      android:layout_toStartOf="@+id/buttonSend" 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:maxLength="120" 
      android:singleLine="true"/> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Send" 
      android:id="@+id/buttonSend" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:background="@null" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageView5" 
      android:src="@drawable/linebreak2px" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 
    </RelativeLayout> 

</RelativeLayout> 
+0

尝试在父容器中设置'android:animateLayoutChanges =“true”'。这应该有效地平滑突然的变化。 – Mithun

尝试设置

android:windowSoftInputMode="adjustResize" 

你的AndroidManifest.xml中,您的活动中,让我知道,如果它

+0

不幸的是,在软键盘完全出现之后'EditText'被锁定到位,并且在完全离开屏幕后被键盘锁定在原始位置。 – QQClientServer

尝试下面的AndroidManifest.xml在您acivity在声明你有你正在

android:windowSoftInputMode="adjustPan" 

的片段,让我知道,如果它的工作原理