Android - 在EditText上onFocus时隐藏LinearLayout

时间:2016-04-15 12:16:53

标签: android android-layout

    <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设置为全屏。当lostFocus在f1textA上时,显示f2,并且f1保持原始高度。 (用于隐藏/显示自定义键盘)

1 个答案:

答案 0 :(得分: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
                }

            }
        });