0

我的Android片段正在使用支持GridLayout來顯示等間距視圖(第一幅圖像)。在我的清單,我如何改變軟鍵盤顯示,以便於調整大小,當我在的EditText挖掘網格佈局和鍵盤顯示(第2圖像),該網格佈局確實從隱藏鍵盤大小調整後,GridLayout不會重置

android:windowSoftInputMode="adjustResize|stateHidden" 

當軟鍵盤被隱藏不會重置回初始大小(最後一張圖片)。

Screenshot showing full screen Screenshot with soft keyboard open Screenshot with soft keyboard closed and GridLayout no longer looking like first screenshot

如何讓網格佈局返回到原來的配置中,第一個屏幕的任何想法?我知道如果我從清單中刪除android:windowSoftInputMode問題就消失了,但這不是我可以在創建此演示的其他應用程序中更改的東西。

這裏是片段的佈局文件:

<android.support.v7.widget.GridLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:grid="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    grid:columnCount="2" 
    grid:rowCount="3" 
    grid:orientation="horizontal"> 

    <EditText 
     android:layout_width="100sp" 
     android:layout_height="80sp" 
     grid:layout_gravity="center" 
     grid:layout_columnWeight="1" 
     grid:layout_rowWeight="1"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="80sp" 
     grid:layout_gravity="center" 
     grid:layout_columnWeight="1" 
     grid:layout_rowWeight="1" 
     android:text="B"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="80sp" 
     grid:layout_gravity="center" 
     grid:layout_columnWeight="1" 
     grid:layout_rowWeight="1" 
     android:text="C"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="80sp" 
     grid:layout_gravity="center" 
     grid:layout_columnWeight="1" 
     grid:layout_rowWeight="1" 
     android:text="D"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="80sp" 
     grid:layout_gravity="center" 
     grid:layout_columnWeight="1" 
     grid:layout_rowWeight="1" 
     android:text="E"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="80sp" 
     grid:layout_gravity="center" 
     grid:layout_columnWeight="1" 
     grid:layout_rowWeight="1" 
     android:text="F"/> 

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

回答

0

我放棄了對網格佈局,並切換到使用ConstraintLayout這沒有問題的作品。

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <EditText 
      android:id="@+id/itemA" 
      android:layout_width="100sp" 
      android:layout_height="80sp" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintLeft_toLeftOf="@+id/itemC" 
      app:layout_constraintBottom_toTopOf="@+id/itemC" 
      app:layout_constraintRight_toRightOf="@+id/itemC"/> 

     <TextView 
      android:id="@+id/itemB" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="80sp" 
      app:layout_constraintLeft_toLeftOf="@+id/itemD" 
      app:layout_constraintBottom_toBottomOf="@+id/itemA" 
      app:layout_constraintRight_toRightOf="@+id/itemD" 
      app:layout_constraintVertical_chainStyle="spread" 
      android:text="B"/> 

     <TextView 
      android:id="@+id/itemC" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="80sp" 
      app:layout_constraintTop_toBottomOf="@+id/itemA" 
      app:layout_constraintBottom_toTopOf="@+id/itemE" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toLeftOf="@+id/itemD" 
      app:layout_constraintHorizontal_chainStyle="spread" 
      android:text="C" 
      app:layout_constraintVertical_bias="0.0"/> 

     <TextView 
      android:id="@+id/itemD" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="80sp" 
      app:layout_constraintLeft_toRightOf="@+id/itemC" 
      app:layout_constraintBottom_toBottomOf="@+id/itemC" 
      app:layout_constraintRight_toRightOf="parent" 
      android:text="D"/> 

     <TextView 
      android:id="@+id/itemE" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="80sp" 
      app:layout_constraintTop_toBottomOf="@+id/itemC" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintRight_toLeftOf="@+id/itemF" 
      android:text="E"/> 

     <TextView 
      android:id="@+id/itemF" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="80sp" 
      app:layout_constraintTop_toBottomOf="@+id/itemD" 
      app:layout_constraintLeft_toRightOf="@+id/itemE" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintRight_toLeftOf="parent" 
      android:text="F"/> 

    </android.support.constraint.ConstraintLayout>