FrameLayout setVisibility not working

I am trying to set FrameLayout to View.GONE along with many other views in response to the screen tilting toward the landscape.

So far this works for all views except ONE FrameLayout. It just wonโ€™t work!

I set it to View.GONE at the same time as all the other views, but it persists:

List<View> viewsToHide = getAllNonFullscreenViews();
for (View v : viewsToHide) {
    v.setVisibility(View.GONE);
}

I checked that the view is actually displayed and sets it to GONE separately. I called clearAnimation () because at some point I was animating it and I heard that this could be a problem.

View dropdownContainer = getActivity().findViewById(R.id.dropdownContainerView);
dropdownContainer.clearAnimation();
dropdownContainer.setVisibility(View.GONE);

I tried to set it to GONE separately in the ui thread. Set breakpoints again and make sure that the view is indeed found and set to GONE.

getActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {
        View dropdownContainer = getActivity().findViewById(R.id.dropdownContainerView);
        dropdownContainer.clearAnimation();
        dropdownContainer.setVisibility(View.GONE);
    }
});

I tried the same thing again, but after a delay

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        View dropdownContainer = getActivity().findViewById(R.id.dropdownContainerView);
        dropdownContainer.clearAnimation();
        dropdownContainer.setVisibility(View.GONE);
    }
}, 3000);

, , GONE?! . , , GONE, -, , .

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        //check the dropdown
        View dropdown = getActivity().findViewById(R.id.dropdownContainerView);
        int visibility = dropdown.getVisibility();
        if (visibility == View.VISIBLE) {
            Log.d("dropdown", "is visible");
        } else if (visibility == View.INVISIBLE) {
            Log.d("dropdown", "is invisible");
        } else if (visibility == View.GONE) {
            Log.d("dropdown", "is gone"); //Runs this
        }
    }
}, 4000);

EDIT: xml

FrameLayout .

, "" .

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/containerFrame">

    <LinearLayout
        android:id="@+id/detailBg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/detail_bg"
        android:orientation="vertical" >

    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/dropdownContainer"
        android:layout_width="fill_parent"
        android:layout_height="48dp">
    </LinearLayout>

    <View
        android:id="@+id/detailSpacer"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/light_gray" />

    <LinearLayout
        android:id="@+id/detailContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" />

    </LinearLayout>
</FrameLayout>

, :

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dropdownContainerView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<RelativeLayout
    android:id="@+id/selectedView"
    android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:background="#ffffff">

<View
    android:id="@+id/grayline1"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_alignParentTop="true"
    android:background="@color/light_gray" />

<View
    android:id="@+id/grayline2"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_alignParentBottom="true"
    android:background="@color/light_gray" />

<TextView
    android:id="@+id/selectedText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:paddingLeft="20dp"
    android:layout_centerVertical="true"
    android:gravity="center"
    android:textSize="18sp"
    android:textColor="#0081C8"/>

</RelativeLayout>
</FrameLayout>

:

FrameLayout parentFrame = (FrameLayout) getActivity().findViewById(R.id.containerFrame);
dropdownView = new DropdownView(getActivity(), options, 0, this);
parentFrame.addView(dropdownView, 1);

EDIT:

, , , . , โ€‹โ€‹ . :

    final Boolean shouldOpen = !isDropdownShowing;

    RelativeLayout selectionView = (RelativeLayout) findViewById(R.id.selectedView);
    final int listHeight = dropdownListView.getHeight();
    final int heightOfSelectionView = selectionView.getHeight();

    TranslateAnimation translateAnimation;
    if (shouldOpen) {
        translateAnimation = new TranslateAnimation (0.0f, 0.0f, heightOfSelectionView - listHeight, 0);
        int y = heightOfSelectionView;
        dropdownListView.setY(y);
    } else {
        translateAnimation = new TranslateAnimation (0.0f, 0.0f, 0, 0 - listHeight);
    }

    translateAnimation.setFillAfter(true);
    translateAnimation.setFillEnabled(true);
    translateAnimation.setDuration(300L);
    translateAnimation.setRepeatCount(0);

    translateAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (shouldOpen) {
                isDropdownShowing = true;
                dropdownListView.setY(heightOfSelectionView);
            } else {
                isDropdownShowing = false;
                dropdownListView.setY(0 - listHeight);
            }

            dropdownListView.clearAnimation();

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    dropdownListView.startAnimation(translateAnimation);
+4
1

, FrameLayout, . , FrameLayout .

, FrameLayout :

for (int i = 0; i < frameLayout.getChildCount(); i++) {
    View v = frameLayout.getChildAt(i);
    v.setVisibility(View.GONE);
    v.postInvalidate();
}

postInvalidate . . , .

+2

All Articles