我有一个FrameLayout(在 a 内)到/从它通过类RelativeLayout添加/删除。My最初与其父级左对齐,有时通过该方法水平偏移。FragmentsFragmentTransactionFrameLayoutFrameLayout.offsetLeftAndRight(int offset)
我发现当我FrameLayout的偏移量并且我提交一个片段事务以Fragment向它添加一个(即FragmentTransaction.add(R.id.myFrameLayout, myNewFragment).commit())时,我的FrameLayout跳转回到它的原始位置,忽略它的偏移量。
任何人都知道为什么会发生这种情况,以及当我添加 a 时如何避免FrameLayout重新定位Fragment?
注意:我使用的是
offsetLeftAndRight(int offset)方法而不是setTranslationX(float translationX)或其他方法,因为我需要我正在做的工作来完成蜂窝之前的工作。