首页 > 解决方案 > AndroidStudio - 在进行片段事务时保持布局参数(高度、宽度)

问题描述

所以我使用 FragmentTransaction 来切换到不同的片段。请看下面的代码。

现在,来自片段的两个膨胀视图都在同一个 FragmentContainerView 中使用。但是由于布局在xml中设置为wrap_content,所以FragmentContainerView的大小发生了变化。

进行交易时如何保持相同的尺寸?谢谢!

    getActivity().getSupportFragmentManager()
            .beginTransaction()

            // Replace the default fragment animations with animator resources
            // representing rotations when switching to the back of the card, as
            // well as animator resources representing rotations when flipping
            // back to the front (e.g. when the system Back button is pressed).
            .setCustomAnimations(
                    R.animator.card_flip_right_in,
                    R.animator.card_flip_right_out,
                    R.animator.card_flip_left_in,
                    R.animator.card_flip_left_out)

            // Replace any fragments currently in the container view with a
            // fragment representing the next page (indicated by the
            // just-incremented currentPage variable).
            .replace(R.id.fragmentFoodCard, new Fragment_FoodCard_Back())

            // Add this transaction to the back stack, allowing users to press
            // Back to get to the front of the card.
            .addToBackStack(null)

            // Commit the transaction.
            .commit();
}

标签: javaandroid-studiofragmentfragmenttransaction

解决方案


推荐阅读