2017-05-20 45 views
0

我有fragment其中包含表單,而這個fragment正在使用shape背景作爲邊框半徑,當彈出鍵盤時這個片段被調整大小。安卓系統 - 當鍵盤彈出時調整片段大小

這screenshoot從fragment鍵盤彈出之前here

這是當鍵盤彈出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(); 
     } 
    }); 

如何解決這個問題?

+0

我想片段總是鍵盤的背面提供幫助。 – AufaDhiya

回答

0

此代碼調整大小視圖

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

} 
+0

它仍然調整大小 – AufaDhiya

+0

只試試WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) –