Android Fragments 如何调整屏幕大小在片段根据软键盘在android?

5f0d552i  于 11个月前  发布在  Android
关注(0)|答案(1)|浏览(72)

当我试图根据软键盘调整片段的屏幕大小时,我面临的问题是,屏幕不是在片段中调整,而是在活动中调整。我尝试了很多方法,但对我不起作用。

以下是我的Fragment activity xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/btnAddCashReceive"
        android:orientation="vertical">

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

            <EditText
                android:id="@+id/edtAmountCashReceive"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="13dp"
                android:layout_marginTop="@dimen/_10sdp"
                android:layout_marginEnd="12dp"
                android:layout_marginBottom="@dimen/_10sdp"
                android:drawableStart="@drawable/currency_rupee_24px"
                android:drawablePadding="@dimen/_10sdp"
                android:fontFamily="@font/poppins_medium"
                android:hint="0"
                android:imeOptions="actionDone"
                android:inputType="numberDecimal"
                android:textSize="42sp" />

            <com.google.android.material.chip.Chip
                android:id="@+id/chip100PercentCashReceive"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="@dimen/_10sdp"
                android:layout_marginStart="13dp"
                android:text="100%" />
        </LinearLayout>

    </LinearLayout>

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnAddCashReceive"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="13dp"
        android:layout_marginEnd="12dp"
        android:text="Add" />
</RelativeLayout>

字符串

以下是我的主要活动文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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"
    tools:context=".BillActivity">

    <FrameLayout
        android:id="@+id/frame_full"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true" />
</androidx.constraintlayout.widget.ConstraintLayout>

mcvgt66p

mcvgt66p1#

尝试将主活动xml文件更改为:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".BillActivity">

<FrameLayout
    android:id="@+id/frame_full"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

字符串

相关问题