2016-04-15 30 views
-1
<RelativeLayout> 
     <LinearLayout 
      android:id="@+id/f1"> 
     <EditText 
         android:id="@+id/f1textA" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:singleLine="true" /> 
     <EditText 
         android:id="@+id/f1textB" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:singleLine="true" /> 
     </LinearLayout> 
    </RelativeLayout> 
    <RelativeLayout> 
     <LinearLayout 
      android:id="@+id/f2"> 
     ... 
     </LinearLayout> 
    </RelativeLayout> 

如何在f1textA上onFocus時隱藏f2 LinearLayout,並將f1設置爲全屏。當迷失在f1textA上時,顯示f2和f1保持原來的高度。 (用於隱藏/顯示自定義鍵盤)如何在onFocus on EditText時隱藏LinearLayout

回答

0

試試這個,

f1textA.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 

       if(hasFocus){ 
       //Hide f2 linear layout and show f1 linear layout 

       } else{ 
       //show f1 linear layout and show f2 linear layout 
       } 

      } 
     }); 
+0

如何設置F1(高度)隱藏之後佔據從F2的空間? –

+0

將父佈局視爲垂直線性佈局,並將f1和f2線性佈局放入其中。 –