我正在更改framelayout中的片段。这是我的主要活动布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res/com.impact.ribony">
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:visibility="gone"
app:pstsIndicatorColor ="#0B0B16"
app:pstsShouldExpand="true" />"
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tabs">
</android.support.v4.view.ViewPager>
</RelativeLayout>
首先我显示登录片段然后用户登录我隐藏了framelayout.Because我正在使用viewpager.If用户想要去设置我正在加载设置片段然后我再次显示framelayout。
但我有问题,您可以在此处查看:http://youtu.be/H6AO7yYusjM
你可以看到用户何时进入设置片段,首先登录片段显示1秒然后设置片段正在加载。如何防止这种情况? (当我尝试更改片段时始终显示最后一个片段1秒而不仅仅是登录片段)
如果用户成功登录,我将使用以下行删除登录片段:
pager.setVisibility(View.VISIBLE);
tabs.setVisibility(View.VISIBLE);
FrameLayout layout = (FrameLayout)findViewById(R.id.container);
layout.setVisibility(View.GONE);
我正在使用以下代码加载登录片段:
FrameLayout layout = (FrameLayout)findViewById(R.id.container);
layout.setVisibility(View.VISIBLE);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
LoginFragment conv = new LoginFragment();
loginObj=LoginFragment.newInstance("asd");
fragmentTransaction.replace(R.id.container, loginObj,"LoginFragment");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
actionBar.hide();
pager.setVisibility(View.GONE);
我正在使用以下代码加载设置片段:
FrameLayout layout=(FrameLayout)findViewById(R.id.container);
pager.setVisibility(View.GONE);
tabs.setVisibility(View.GONE);
FragmentManager fragmentManager=getSupportFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
SettingsFragment conv=new SettingsFragment();
SettingsFragment.newInstance(LOGGED_USERNAME);
fragmentTransaction.replace(R.id.container,conv);
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
layout.setVisibility(View.VISIBLE);