Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 网格布局不';从隐藏键盘调整大小后不能重置_Android_Android Layout_Android Softkeyboard_Android Gridlayout - Fatal编程技术网

Android 网格布局不';从隐藏键盘调整大小后不能重置

Android 网格布局不';从隐藏键盘调整大小后不能重置,android,android-layout,android-softkeyboard,android-gridlayout,Android,Android Layout,Android Softkeyboard,Android Gridlayout,我的Android片段正在使用支持来显示等距视图(第一幅图像)。在我的清单中,我正在更改软键盘的显示方式,以便在我点击EditText并显示键盘时调整GridLayout的大小(第二幅图像): 隐藏软键盘时,GridLayout不会重置回其初始大小(最后一幅图像) 关于如何让GridLayout在第一个屏幕截图中回到其原始配置,您有什么想法吗?我知道如果我从清单中删除android:windowSoftInputMode,问题就会消失,但这不是我可以在创建此演示的另一个应用程序中更改的内容

我的Android片段正在使用支持来显示等距视图(第一幅图像)。在我的清单中,我正在更改软键盘的显示方式,以便在我点击EditText并显示键盘时调整GridLayout的大小(第二幅图像):

隐藏软键盘时,GridLayout不会重置回其初始大小(最后一幅图像)

关于如何让GridLayout在第一个屏幕截图中回到其原始配置,您有什么想法吗?我知道如果我从清单中删除
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>

我放弃了GridLayout,转而使用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>


显然,
GridLayout.Axis.layout()中有一个bug
(在
onLayout()中调用)

如果确实需要使用
GridLayout
调用
requestLayout
来触发其私有方法,那么
invalidateStructure()
似乎可以解决这个问题

class FixedGridLayout : GridLayout {
    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context) : super(context)

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        if (changed) {
            post {
                requestLayout()
            }
        }
    }
}
class FixedGridLayout : GridLayout {
    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context) : super(context)

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
        if (changed) {
            post {
                requestLayout()
            }
        }
    }
}