sal*_*lih 5 android android-fragments fragmenttransaction
我正在开发一个使用片段的应用程序,上周我的测试设备进行了lolipop更新.当我在lolipop设备上测试我的应用程序时,我看到Fragment Transaction的替换方法无法正常工作.
虽然在Kitkat版本上一切都很好,但它在Lolipop版本中令人困惑.
为了解释我的情况,我添加了一些图片.
--First Screen ---------------------------- KitKat ----------------- - - - - - - - - - - 棒糖 - - - - - - -

正如你所看到的,当我使用时kitkat,一切都很好,但是一旦我使用lolipop片段事务替换就会令人困惑.
这是我的按钮代码;
mButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FeedbackFragment mFragmentFeedBack = new FeedbackFragment();
android.app.FragmentManager fm = getFragmentManager();
fm.executePendingTransactions();
android.app.FragmentTransaction fragmentTransaction = fm.beginTransaction();
if (mFragmentFeedBack.isVisible()) {
fragmentTransaction.hide(mFragmentFeedBack);
} else {
if (!mFragmentFeedBack.isAdded()) {
fragmentTransaction.replace(R.id.containerfragment, mFragmentFeedBack);
}
fragmentTransaction.show(mFragmentFeedBack);
}
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的xml;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="117dp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerfragment">
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
编辑: Kitkat版本在平板电脑上运行,但我在手机上尝试了我的应用程序(Kitkat版本)结果是一样的.没有变化.
谢谢.
可能的问题可能是代码:
if (mFragmentFeedBack.isVisible())
Run Code Online (Sandbox Code Playgroud)
我不建议使用此方法来检查可见性。根据文档 @ Fragment isVisible(),它说
...这意味着:(1) 已添加,(2) 其视图已附加到窗口,并且 (3) 未隐藏。
这部分句子不是很清楚。我怀疑 KitKat 说它不可见,但 Lollipop 说它可见,并且我同意 Lollipop 的实现。KitKat 说片段已添加(是)、视图已附加(是)、隐藏(不是真的!)。不管你信不信,这实际上是其他 GUI 库的 GUI 问题!
目前可能的解决方案:
| 归档时间: |
|
| 查看次数: |
743 次 |
| 最近记录: |