我在问之前已经浏览了几天,但找不到任何可以完全回答我问题的内容。我在一个框架内有两个碎片。当我从一个片段切换到另一个片段时,当帧中有另一个片段时,它会滞后。我试图在转换时隐藏它但看起来不太好。
MainActivity(Frame):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ft = getSupportFragmentManager().beginTransaction();
HomePage homeFrag = new HomePage(); //create game fragment
ft.add(R.id.activity_main, homeFrag, "Home");
ft.show(homeFrag);
ft.commit();
片段1:
startNewGame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Thread thread = new Thread()
{
@Override
public void run()
{
//ft.hide(frag);
ft.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_right, R.anim.exit_to_left);
ft.replace(R.id.activity_main, new PlayGame(), "PlayGame");
ft.addToBackStack("Home");
ft.commit();
}
};
thread.run();
}
});
片段2:
public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.play_game, container, false);
v.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if(keyEvent.getKeyCode() == keyEvent.KEYCODE_BACK)
{
ft = getFragmentManager().beginTransaction();
getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
return true;
} else
{
return false;
}
}
});
return v;
感谢您的帮助!
答案 0 :(得分:0)
感谢user7568042,问题只是模拟器设置不够高。低设置使得模拟器显示fps滞后而不是代码问题。补救措施是增加设置并重新启动模拟器。