I have this layout:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.components.game.GameView android:id="@+id/game_id" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <RelativeLayout android:id="@+id/ChatLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:visibility="invisible" android:focusable="true" android:focusableInTouchMode="true" > <Button android:id="@+id/ChatCancelButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="X" /> <Button android:id="@+id/ChatOkButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="OK" /> <EditText android:id="@+id/ChatEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@+id/ChatOkButton" android:layout_toRightOf="@+id/ChatCancelButton" android:maxLength="50" android:singleLine="true" /> </RelativeLayout> </RelativeLayout>
This is a RelativeLayout over the canvas. This is invisible during startup, but when the user clicks the button, the layout should become visible. The problem is that it does not become visible. There is a layout, but he just does not draw. If I click on the position where the layout should be displayed, it receives the event and opens the keyboard, but does not draw the entire layout. What is the problem?
If I set RelativeLayout to visible at the beginning, it works fine. it shows the layout, and if I switch between invisible and visible, it works great.
I made a workaround that almost always works. I start the layout visible, not the one in oncreate:
chatLayout.postDelayed(new Runnable() { @Override public void run() { chatLayout.setVisibility(View.INVISIBLE); } }, 50);
But I donβt like it and I want to understand what the problem is.
Code:
It starts with a canvas button that sends a message to the handler:
public void showInputLayout() { Message.obtain(gameHandler, SHOW_INPUT_LAYOUT).sendToTarget(); }
In the handler:
case SHOW_INPUT_LAYOUT: gameActivity.setChatVisibility(true); break;
setChatVisibility:
public void setChatVisibility(boolean isVisible) { int visible = isVisible ? View.VISIBLE : View.INVISIBLE; chatLayout.setVisibility(visible); if(isVisible){ chatEditText.setFocusable(true); chatEditText.requestFocus(); } }
source share