Android Fragments Android -弹出键盘时调整片段大小

2w2cym1i  于 2023-02-08  发布在  Android
关注(0)|答案(2)|浏览(136)

我有fragment,其中包含的形式,这fragment是使用shape背景的边界半径,当键盘弹出这个片段的大小。
键盘弹出here之前fragment的屏幕截图
这是当键盘弹出here
这是我的片段布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_frm_jadwal_kuliah"
    android:background="@drawable/fragment_border"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
tools:context="me.citrafa.mycollegeassistant.Activity.Fragment.frmJadwalKuliah">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <me.citrafa.mycollegeassistant.CustomWidget.tvMuseo
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textAlignment="center"
        android:textColor="@color/accent"
        android:textSize="20sp"
        android:maxLines="2"
        android:text="Jadwal Kuliahku"/>
    <android.support.v7.widget.AppCompatSpinner
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/mySpinner"
        android:layout_marginTop="20dp"
        android:entries="@array/hari"
        android:id="@+id/spinnerHari"/>
    <me.citrafa.mycollegeassistant.CustomWidget.etMuseo
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="20sp"
        android:id="@+id/txtMakul"
        style="@style/myEditTextForm"
        android:hint="Nama Matakuliah"/>
    <me.citrafa.mycollegeassistant.CustomWidget.etMuseo
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="16sp"
        android:id="@+id/txtRuangan"
        style="@style/myEditTextForm"
        android:hint="Ruangan Kuliah"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <me.citrafa.mycollegeassistant.CustomWidget.etMuseo
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textSize="16sp"
            android:id="@+id/txtJam"
            style="@style/myEditTextForm"
            android:hint="Jam Kuliah"/>
        <me.citrafa.mycollegeassistant.CustomWidget.etMuseo
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="5dp"
            android:textSize="16sp"
            android:id="@+id/txtKelas"
            style="@style/myEditTextForm"
            android:hint="Kelas"/>
    </LinearLayout>
    <me.citrafa.mycollegeassistant.CustomWidget.etMuseo
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:textSize="16sp"
        android:id="@+id/txtDosen"
        style="@style/myEditTextForm"
        android:hint="Nama Dosen"/>

</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btnSimpan"
    app:srcCompat="@drawable/ic_done_white_24px"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"/>
</RelativeLayout>

这是形状“fragment_border”:

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"   >

    <solid
        android:color="#fff" >
    </solid>

    <stroke
        android:width="1dp"
        android:color="#C4CDE0" >
    </stroke>

    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"    >
    </padding>

    <corners
        android:radius="8dp"   >
    </corners>

</shape>

这就是我所说的片段:

fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bundle bundle = new Bundle();
            bundle.putInt("idJK",0);
            frmJadwalKuliah f = new frmJadwalKuliah();
            f.setArguments(bundle);
            getFragmentManager().beginTransaction().add(R.id.tabJadwalKuliah,f).addToBackStack(null).commit();
            fab.hide();
        }
    });

如何解决这个问题?

lb3vh1jj

lb3vh1jj1#

您必须在清单中(包含片段的Activity内)添加以下行android:windowSoftInputMode=“adjustPan”

<activity
            android:name=".MainActivity"
            android:exported="true"
            android:configChanges="orientation"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan"
            android:label="@string/app_name" />
baubqpgj

baubqpgj2#

此代码提供调整视图大小的帮助

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

}

相关问题