gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:52:30 25 4
gpt4 key购买 nike

我关注了这个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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com