Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android animate view outside fragment is getting clipped

I have a view in a fragment. This fragment is within a FrameLayout. I want to animate this view moving outside the fragment borders. However, the view always get clipped when crossing the border. I have tried by setting android:clipChildren="false" and android:clipToPadding="false" to everything, but I can't get it to work.

Is this even possible to do?

like image 230
Hazneliel Avatar asked Feb 28 '14 21:02

Hazneliel


2 Answers

I had the similar problem with fragments and put android:clipChildren="false" and android:clipToPadding="false" on all the levels in my hierarchy, but it was still not working. The trick that worked for me was to add this override in my fragment code:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ViewGroup vg = (ViewGroup) view;
    vg.setClipChildren(false);
    vg.setClipToPadding(false);
}

Hope this helps...

P.S. the credit should go to this answer

like image 98
frangulyan Avatar answered Nov 03 '22 05:11

frangulyan


frangulyan You're missing the other bit of code from your credited answer. The below solution worked for me.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false);
    //This can be done in XML
    rootView.setClipChildren(false);
    rootView.setClipToPadding(false);
    return rootView;
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
//This is the NoSaveStateFrameLayout - force it to not clip
FrameLayout frameLayout = (FrameLayout) getView();
frameLayout.setClipChildren(false);
frameLayout.setClipToPadding(false);

}

like image 42
Barrie Galitzky Avatar answered Nov 03 '22 05:11

Barrie Galitzky