fragment跳转到fragment 位置不对

我想要的结果:

MyFragment1类代码如下:
public class MyFragment1 extends Fragment implements View.OnClickListener{
ImageButton ib_update;
public MyFragment1() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.main_tab_home,container,false);
ib_update=(ImageButton) view.findViewById(R.id.ib_update);
ib_update.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
switch (v.getId()) {
case R.id.ib_update: //按钮
ft.replace(R.id.ll_home,new TheLatestFragment());
ft.commit();
break;
}
}
}
MyFragment1类的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/ll_home">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#FF0000"
android:gravity="center"
android:text="@string/tab_menu_home"
android:textSize="20sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="221dip">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="210dp" >
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="200dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dip"
android:layout_gravity="bottom"
android:background="#33000000"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_image"
android:textColor="@android:color/white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:orientation="horizontal" >
<View
android:id="@+id/dot_0"
android:layout_width="5dip"
android:layout_height="5dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/dot_focused"/>
<View
android:id="@+id/dot_1"
android:layout_width="5dip"
android:layout_height="5dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/dot_normal"/>
<View
android:id="@+id/dot_2"
android:layout_width="5dip"
android:layout_height="5dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/dot_normal"/>
<View
android:id="@+id/dot_3"
android:layout_width="5dip"
android:layout_height="5dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/dot_normal"/>
<View
android:id="@+id/dot_4"
android:layout_width="5dip"
android:layout_height="5dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/dot_normal"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="74dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/rg_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/ib_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/button_culture"/>
<ImageButton
android:id="@+id/ib_cuture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/button_phone"/>
<ImageButton
android:id="@+id/ib_team"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/button_update"/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
TheLatestFragment类和布局,我就不贴出来了
相关推荐
android的关于fragment,实现Activity之间的跳转
android的关于fragment的demo,很适合初学者,可以运行,页面效果也不错,可以实现各个Activity之间的跳转,可以取代tabhost
Android开发fragment界面上点击按钮跳转
Android应用中的fragement跳转demo,跳转是从一个子fragement上的按钮跳转到其他子fragement上,不是通过导航栏上的按钮
fragment activity与fragment相互传值 fragment与fragment跳转
自己项目中用到fragment搭建框架,从网上找得一个demo,实现activity与fragment相互传值;fragment与fragment跳转。跟大家分享
android+Fragment实现页面的局部跳转
android平板电脑开发,使用Fragment实现页面的局部跳转,像管理系统一样,点击左边的连接实现右边页面的跳转
Android从Fragment跳转到其他Activity的简单实例
为了更好的理解以下内容,我们需要简单了解一下Fragment的动态注册方法 Android——Fragment的静态注册和动态注册 为了实现从Fragment跳转到其他Activity,下面需要创建以下文件: 第一步:简单编写布局文件fragment_activity.xml和抽象类TemplateFragmentActivity.java代码如下: fragment_activity.xml <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/r


