gpt4 book ai didi

android - 防止软键盘将内容推到屏幕外

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

我有这样的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:weightSum="10" >

<TextView
android:id="@+id/textViewTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="@string/fraga"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="40sp" />

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/layout_input"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textViewTitle"
android:layout_margin="10dp"
android:background="#DDD"
android:isScrollContainer="false"
android:padding="10dp" >

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
android:id="@+id/textViewQuestion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="18"
android:adjustViewBounds="true"
android:scaleType="fitCenter" android:contentDescription="@string/image"/>
</LinearLayout>
</ScrollView>

<Button
android:id="@+id/buttonPrev"
style="@style/white_button"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/tillbaka" />

<Button
android:id="@+id/buttonNext"
style="@style/white_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="@+id/buttonPrev"
android:text="@string/nasta" />

<LinearLayout
android:id="@id/layout_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/buttonPrev"
android:orientation="vertical" >

<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:digits="0123456789(),.*-+/=:"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="@string/svar"
android:inputType="number|numberSigned|numberDecimal"
android:singleLine="true"
android:textSize="28sp"
>

<requestFocus />
</EditText>

<Spinner
android:id="@+id/spinner"
style="@android:style/Widget.Spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:visibility="gone" />
</LinearLayout>

</RelativeLayout>

当我单击编辑文本时,软键盘会弹出并按预期将编辑文本推到键盘上方。唯一的问题是它还会将编辑文本上方的内容向上推。有什么办法可以防止这种情况发生吗?

最佳答案

manifest.xml 中的 activity 标记内使用这段代码。

android:windowSoftInputMode="adjustPan"

像这样:

<activity
android:label="activity_name"
android:name=".MainActivity" android:windowSoftInputMode="adjustPan">
</activity>

关于android - 防止软键盘将内容推到屏幕外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15865402/

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