我是非常新的android和我卡在从主要活动调用片段。关键是每次我说更换(时间)旧的FrameLayout的新布局,它只是增加了原来并没有替换视图从主要活动调用片段添加片段
我activity_main.xml中是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash_screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jaggz.gurudawaraapp.MainActivity" >
<FrameLayout
android:id="@+id/container_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="126dp"
android:layout_marginTop="29dp"
android:src="@drawable/splash" />
<TextView
android:id="@+id/splash_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="25dp"
android:paddingLeft=" 30dp"
android:paddingRight="10dp"
android:paddingTop="300dp"
android:text="@string/splash_text"
android:textSize="@dimen/splash_text_size"
android:textStyle="bold|italic"
android:typeface="sans" />
</FrameLayout>
</RelativeLayout>
我是使用上述帧布局容器更换为改变片段
内容我的代码如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.app = (App) getApplication().getApplicationContext();
init();
}
private void init() {
Fragment frag = new SplashLoginFragment();
android.support.v4.app.FragmentManager fm1 = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft1 = fm1.beginTransaction();
ft1.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft1.replace(R.id.container_main, frag);
ft1.commit();
}
和我对SplashLoginFragment 一个新的XML有人能帮助我走出
你不应该有framelayout中的图像视图和文本视图。框架布局是为了容纳一个组件。如果您确实需要使用可视化切换或飞溅片段,则可以使用它。 – Spidy 2014-09-21 06:32:35