次のようなレイアウトを作成します: 編集テキストと 3 つのボタン: (水平レイアウトがなくなったと定義されていることに注意してください。つまり、表示されません。
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"</EditText>
<LinearLayout
android:id="@+id/horizontal_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/horizontal_layout"
android:visibility="gone">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
アクティビティでは、次のようなものがあります。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
EditText edit = (EditText) findViewById(R.id.teste_editText1);
final LinearLayout layout = (LinearLayout)findViewById(R.id.horizontal_layout);
edit.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View paramView, boolean paramBoolean) {
if (paramBoolean) {//if is focused
layout.setVisibility(View.VISIBLE);
} else {
layout.setVisibility(View.GONE);
}
}
});
}