mardi 4 août 2015

Android LinearLayout items overlap each other when one changes visibillity properties

I have a view with a LinearLayout which contains a bunch of items to show. In initialization code I add these items into layout.

for(int i = 0; i < n; i++) {
    View view = new SwitchButton(mTexts.get(i));
    mLinearLayout.add(view);
}

On top of this LinearLayout I have a TabLayout with several tabs. Whenever a user switches to another tab I set visibility property to each item in the layout according to to a specific tab.

@Override
public void onTabSelected(Tab tab) {
    if (tab.getPosition() != mLastSelectedTab) {
        for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
            View item = mLinearLayout.getChildAt(i);
            if (isVisibleInTab(tab.getPosition(), i) {
                 item.setVisibility(View.VISIBLE);
            } else {
                 item.setVisibility(View.GONE);
            }
        }
    }
}

But when a user changes tab for a short period of time linear layout items overlap one another. Even if I set

android:animateLayoutChanges="true"

in my layout, overlapping still occurs.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire