gpt4 book ai didi

java - 修复软键盘上方的布局

转载 作者:行者123 更新时间:2023-11-29 18:50:51 25 4
gpt4 key购买 nike

我知道这个问题在互联网上已经存在很久了,但对我来说似乎没有任何效果。

怎么了

enter image description here enter image description here

如屏幕截图所示,具有微调器的布局未向上推,而是与软键盘重叠。我希望此布局在弹出时正好位于键盘上方。

我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical"
tools:context="believe.cht.speak.MainActivity">

<ImageView
android:id="@+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="@drawable/ic_bubble"
android:tint="@color/blue" />

<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />

<ImageView
android:id="@+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="@drawable/shadow" />

<RelativeLayout
android:id="@+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/blue">

<Spinner

android:id="@+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />

</RelativeLayout>

</LinearLayout>

我尝试过的

android:windowSoftInputMode="adjustResize"

android:windowSoftInputMode="adjustPan" //in the manifest, also tried combining the two

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); //in the activity

<item name="android:windowActionBarOverlay">true</item> //in styles.xml

最佳答案

试试这个

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">

<ImageView
android:id="@+id/logo"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
android:src="@drawable/ic_message" />

<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|start"
android:hint="Start typing..."
android:padding="8dp" />

<ImageView
android:id="@+id/shadow"
android:layout_width="match_parent"
android:layout_height="6dp"
android:src="@drawable/ic_camera" />

<RelativeLayout
android:id="@+id/spinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary">

<Spinner

android:id="@+id/spinner"
android:layout_width="200dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true" />

</RelativeLayout>

</LinearLayout>
</ScrollView>

list 文件

    <activity android:name=".MyActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</activity>

输出

enter image description here enter image description here

关于java - 修复软键盘上方的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50987381/

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