2017-08-07 84 views
0

我正在嘗試創建一個聊天應用程序。聊天佈局目前看起來是這樣的調整軟鍵盤啓動的視圖

No Keyboard

相應的佈局文件是

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:fillViewport="true" 
    android:layout_height="match_parent"> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.nirmal.chatadapter.MainActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/colorPrimary"> 
     <de.hdodenhof.circleimageview.CircleImageView 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/profile_image" 
      android:layout_width="40dp" 
      android:layout_height="wrap_content" 
      android:src="@drawable/iconuser" 
      app:civ_border_width="2dp" 
      app:civ_border_color="@color/White"/> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginStart="@dimen/marginLeftForToolbar" 
      android:orientation="vertical"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/White" 
       android:text="UserName Here" 
       android:layout_marginTop="@dimen/marginTopBottomForBubble" 
       android:id="@+id/user_name" 
       android:textSize="@dimen/textMedium"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/White" 
       android:text="User details Here" 
       android:layout_marginTop="@dimen/marginTopBottomForBubble" 
       android:id="@+id/user_details" 
       android:textSize="@dimen/textSmall"/> 
     </LinearLayout> 

    </android.support.v7.widget.Toolbar> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/toolbar" 
     android:layout_marginTop="@dimen/recyclerViewMargin" 
     android:isScrollContainer="true" 
     android:id="@+id/chatRecycler" 
     android:layout_above="@+id/chatBoxAndSend"> 
    </android.support.v7.widget.RecyclerView> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" 
     android:layout_marginBottom="5dp" 
     android:id="@+id/chatBoxAndSend"> 
     <EditText 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:minWidth="50dp" 
      android:maxWidth="50dp" 
      android:id="@+id/chatBox" 
      android:paddingStart="@dimen/cardViewPadding" 
      android:background="@drawable/rounded_chat_box" 
      android:layout_margin="@dimen/marginForChatBox" 
      /> 
     <Button 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.2" 
      android:background="@drawable/oval_button" 
      android:minWidth="50dp" 
      android:maxWidth="50dp" 
      android:text="Send" 
      android:imeOptions="flagNoExtractUi" 
      android:id="@+id/chatSendButton" 
      android:layout_margin="@dimen/marginForChatBox" 
      android:textColor="@color/Black" 
      /> 
     <!--<ImageView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.1" 
      android:id="@+id/send_button" 
      android:src="@drawable/send" 
      android:background="@drawable/oval_button" 
      android:layout_marginBottom="@dimen/marginForChatBox" 
      android:layout_marginTop="@dimen/marginForChatBox" 
      android:layout_marginEnd="@dimen/marginForChatBox" 
      /> 
     <de.hdodenhof.circleimageview.CircleImageView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.1" 
      android:id="@+id/send_button" 
      android:src="@drawable/send" 
      app:civ_border_width="2dip" 
      android:layout_marginEnd="@dimen/marginForChatBox" 
      app:civ_border_color="@color/greenChatColor"/>--> 


    </LinearLayout> 
</RelativeLayout> 
</ScrollView> 

當我打開軟鍵盤的佈局看起來喜歡這個

with keyboard

我有在我的清單文件中加入了這個

android:windowSoftInputMode="adjustPan|stateHidden" 

輸出不是我所期望的。我想讓recyclerview在屏幕中心動態調整大小,工具欄和edittext保持完全可見。

正如您所看到的那樣,工具欄已被推高,即使滾動時也不可見。 edittext被鍵盤給出的建議部分隱藏。我看到的一些帖子要求我添加一個我曾經做過的滾動視圖,並且仍然是相同的結果。我怎麼解決這個問題?

回答

0

flagPanPan是錯誤的。使用adjustResize代替:

android:windowSoftInputMode="adjustResize|stateHidden" 

adjustPan做什麼是相當於擴大比屏幕更大的圖片,然後平移 - 即移動圖片,讓你看到它的不同部分。 (比如谷歌地圖中的地圖)。