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

标签 android android-layout imageview android-linearlayout android-layout-weight

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

enter image description here

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

enter image description here

我怎样才能使 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 默认行为会调整 View 大小以为键盘腾出空间。 您可以在 list 文件中更新它 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

关于android - 如果我在键盘弹出时设置 linearlayout 权重,它会调整其大陆的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37946903/

相关文章:

java - 尽管我下载了 jar 文件,但我无法导入改造 RestAdapter

java - Android 在 OnMAMCreate 方法处循环

android - 自定义 View 的主题样式

android - setColorFilter 不工作

android - ImageView setImageDrawable 导致绘制空白图像

java - 在模拟器中运行 Android 应用程序时没有布局

android - 内测如何下载 "Android"预发布的App build?

设置文本后,Android TextSwitcher 无法换行内容宽度

java - Android AlertDialog 设置项目对齐中心

java - 完成我开始的操作后如何删除监听器? (JAVA)