- 一.top和bottom
- 1.top
- 2.bottom
- 二.创建四个Fragment,分别对应“聊天”、“联系人”、“朋友圈”、“我的”这四个xml文件
- 三.最后效果图:
- 四.我的gitee库: [https://gitee.com/jiang-zhongwen/jiang-zhongwen](https://gitee.com/jiang-zhongwen/jiang-zhongwen/).
需要一个linearlayout和一个text View
2.bottom需要的控件以及呈现效果如下图所示:
这里给出一个LineaLayout示例代码:
二.创建四个Fragment,分别对应“聊天”、“联系人”、“朋友圈”、“我的”这四个xml文件
其中wexinFragment函数如下:
package com.example.wechat;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class wexinFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_wexin, container, false);
}
}
各个java文件及Fragment文件如下:
以下是mainactivity函数,具体的函数定义见最后面的链接
public class MainActivity extends AppCompatActivity {
private Fragment wexinFragment=new wexinFragment();
private Fragment myFragment=new myFragment();
private Fragment worldFragment=new worldFragment();
private Fragment friendFragment=new friendFragment();
private FragmentManager fm;
private LinearLayout linearLayout1,linearLayout2,linearLayout3,linearLayout4;
private TextView textView1,textView2,textView3,textView4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
linearLayout1 = findViewById(R.id.LinearLayout_wexin);
linearLayout2 = findViewById(R.id.LinearLayout_friend);
linearLayout3 = findViewById(R.id.LinearLayout_world);
linearLayout4 = findViewById(R.id.LinearLayout_my);
linearLayout1.setOnClickListener(this::onClick);
linearLayout2.setOnClickListener(this::onClick);
linearLayout3.setOnClickListener(this::onClick);
linearLayout4.setOnClickListener(this::onClick);
initFragment();
showfragment(0);
}
三.最后效果图:
四.我的gitee库: https://gitee.com/jiang-zhongwen/jiang-zhongwen.


