如果我在键盘弹出时设置 linearlayout 权重,它会调整其大陆的大小

if I set linearlayout weight when keyboard pops it resizes its continent

我按照这个 example 并设法将 fab 按钮放在正确的位置

但是当我按下编辑文本键盘时弹出并且它弄乱了布局权重

我怎样才能让 ImageView 保持静态并且当键盘打开时它会保持相同的大小?

XML:

<android.support.design.widget.CoordinatorLayout    
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"
android:background="@color/white"
android:focusableInTouchMode="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/ViewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@color/colorPrimary"
android:orientation="horizontal">

<ImageView
    android:id="@+id/imgview"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="@color/light_blue"
    android:scaleType="centerCrop"
    android:src="@android:drawable/ic_menu_camera"
    android:layout_gravity="top|center_horizontal"
    />

</LinearLayout>

<LinearLayout
    android:id="@+id/ViewB"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.3"
    android:orientation="horizontal">
</LinearLayout>
</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/add_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/ViewA"
    android:clickable="true"
    app:layout_anchorGravity="bottom|right"
    app:elevation="5dp"
    app:pressedTranslationZ="0dp"
    android:src="@android:drawable/ic_menu_camera"/>


</android.support.design.widget.CoordinatorLayout>

这是因为 android 视图将调整大小以为键盘腾出空间的默认行为。 您可以在清单文件中更新它 android:windowSoftInputMode 的可能值 --> adjustResize, adjustPan, adjustUnspecified

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

More info