1

I have a SurfaceView with a LinearLayout which hides or shows if you click on the SurfaceView. The problem is that the SurfaceView is not refreshed so if the setVisibility(View.VISIBLE) actually doesn't work.

This is the code I'm using:

sv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v)
            {
                Log.d("MainActivity-onCreate-onClick-buttons",
                        buttonsVisibility.toString());
                if (buttonsVisibility)
                {
                    linearLayoutButtons.setVisibility(View.INVISIBLE);
                    buttonsVisibility = false;
                } else
                {
                    linearLayoutButtons.setVisibility(View.VISIBLE);
                    buttonsVisibility = true;
                }

            }
        });

By default buttonVisibility is set to false and the first time I click the view it actually is so so the logic is consistent, the only problem is that the setVisibility seems to have no effect. Only if I turn on/off the screen I can see the layout displayed correctly and then working properly. Why I need to turn the screen off to refresh the UI? Shouldn't it refresh automatically after the setVisibility?

Thank you very much

4

1 に答える 1

0

理由はわかりませんが、ボタンを ImageButton に変更すると機能しますが、どこに配置してもボタンが間違った「z-index」で表示されます。「z-index」を修正するには、一度クリックする必要があります。setVisibility(View.INVISIBLE) を setVisibility(View.GONE) に変更すると、すべて正常に動作します。

これが同じ問題を抱えている人の助けになることを願っています。

于 2013-10-02T09:24:55.770 に答える