zoukankan      html  css  js  c++  java
  • 使用fragment添加底部导航栏

    切记:fragment一定要放在framlayout中,不然不会被替换完全(就是切换之后原来的fagment可能还会存在)

    main.xml

    <LinearLayout 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"
    android:background="#ffffff"
    android:orientation="vertical">


    <FrameLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
       >
    <fragment
    android:name="com.liu25.asmallpark.Fragment.Fragment_1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout="@layout/fragment_1" />
    </FrameLayout>

      <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content">
      <!--四个Button>

      <LinearLayout/>



    <LinearLayout/>

    fragment_1.xml(灰色背景)

    <?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:background="#f3f3f3"
    android:orientation="vertical">
    </LinearLayout>

    fragment_2.xml(黑色背景)

    <?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:background="#000000"
    android:orientation="vertical">
    </LinearLayout>

    main.java
    在Button点击事件里面:
      

    FragmentManager fragmentManager = getFragmentManager();//
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.content, fragment_1);
    transaction.commit();

    彩蛋:在fragment中获得Context:view.getContext()

     
  • 相关阅读:
    java开发_图片截取
    一位台湾软件工程师的心路历程
    WCF Basic(2)服务契约继承
    状态模式(State Pattern)
    .NET Remoting Basic(9)上下文(CallContext)
    访问者模式(Visitor Pattern)
    命令模式(Command Pattern)
    .NET Remoting Basic(10)创建不同宿主的客户端与服务器端
    责任链模式(Chain of Responsibility Pattern)
    消息队列(Message Queuing)
  • 原文地址:https://www.cnblogs.com/judes/p/5753171.html
Copyright © 2011-2022 走看看