一、作业目标
app根本页面包罗以下三个内容:首页(3-4个tab页面),列表页面,详情页面,从首页可以点击进入列表页面,点击列表的某一行可以进入详情页面
二、工具
Android studio
三、计划思绪
微信页面包含聊天,联系人,位置,设置四个tab界面,主界面总体分为上中下三个部分,使用recycleview在联系人界面实现列表结果,用来显示联系人详细信息
详细文件为tab1,2,3,4;fragment1,2,3,4对应;上中下结果由top tab bottom实现;
最后由main.xml整合
详细文件展示:
代码如下:
top.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="wrap_content">
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="@color/black"
- android:gravity="center"
- android:text="微信"
- android:textColor="@color/white"
- android:textSize="40sp" />
- </LinearLayout>
复制代码 item.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="wrap_content">
- <TextView
- android:id="@+id/textView6"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:gravity="center"
- android:text="TextView"
- android:textColor="@color/black"
- android:textSize="35sp" />
- </LinearLayout>
复制代码 bottom.xml
main.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:orientation="vertical">
- <include layout="@layout/top" />
- <FrameLayout
- android:id="@+id/content1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- </FrameLayout>
- <include
- android:id="@+id/content"
- layout="@layout/bottom" />
- </LinearLayout>
复制代码 tab页面代码类似
展示tab1例子以及加入了recycleview的tab2(如果详情页加到tab1,3,4中同理)
tab1
- <?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">
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_weight="1"
- android:gravity="center"
- android:text="这是聊天界面"
- android:textSize="50sp" />
- </LinearLayout>
复制代码 tab2
- <?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">
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/recycleView"
- android:layout_width="388dp"
- android:layout_height="701dp"
- android:layout_marginStart="8dp"
- android:layout_marginTop="8dp"
- />
- </LinearLayout>
复制代码 fragment页面类似
展示fragment1例子以及加入了recycleview的fragment2(如果详情页加到fragment1,3,4中同理)
fragment1
- package com.example.myapplication;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import androidx.fragment.app.Fragment;
- import com.example.myapplication.R;
- public class Fragment1 extends Fragment {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- return inflater.inflate(R.layout.tab1, container, false);
- }
- }
复制代码 fragment2
- package com.example.myapplication;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import androidx.fragment.app.Fragment;
- import androidx.recyclerview.widget.LinearLayoutManager;
- import androidx.recyclerview.widget.RecyclerView;
- import java.util.*;
- public class Fragment2 extends Fragment {
- Context context;
- List list;
- RecyclerView recyclerView;
- Myadapter myadapter;
- @SuppressLint("MissingInflatedId")
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View view = inflater.inflate(R.layout.tab2, container, false);
- context = view.getContext();
- recyclerView = view.findViewById(R.id.recycleView);
- list = new ArrayList();
- for(int i=0;i<9;i++){
- list.add("这是第"+i+"行数据");}
- myadapter = new Myadapter(context, list);
- recyclerView.setAdapter(myadapter);
- LinearLayoutManager manager = new LinearLayoutManager(context);
- manager.setOrientation(LinearLayoutManager.VERTICAL);
- recyclerView.setLayoutManager(manager);
- return view;
- }
- }
复制代码 myadapter类
- package com.example.myapplication;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.TextView;
- import androidx.annotation.NonNull;
- import androidx.recyclerview.widget.RecyclerView;
- import com.example.myapplication.R;
- import java.util.List;
- import java.util.zip.Inflater;
- public class Myadapter extends RecyclerView.Adapter<Myadapter.Myholder> {
- Context context1;
- List<String> list1;
- public Myadapter(Context context, List list){
- context1=context;
- list1=list;
- }
- @NonNull
- @Override
- public Myholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- View view=LayoutInflater.from(context1).inflate(R.layout.item,parent,false);
- Myholder myholder=new Myholder(view);
- return myholder;
- }
- @Override
- public void onBindViewHolder(@NonNull Myholder holder, int position) {
- holder.textView.setText(list1.get(position));
- }
- @Override
- public int getItemCount() {
- return list1.size();
- }
- protected class Myholder extends RecyclerView.ViewHolder {
- TextView textView;
- public Myholder(@NonNull View itemView) {
- super(itemView);
- textView=itemView.findViewById(R.id.textView6);
- }
- }
- }
复制代码 recycleviewactivity
- package com.example.myapplication;
- import android.os.Bundle;
- import androidx.activity.EdgeToEdge;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.graphics.Insets;
- import androidx.core.view.ViewCompat;
- import androidx.core.view.WindowInsetsCompat;
- public class recycleviewActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- EdgeToEdge.enable(this);
- setContentView(R.layout.activity_recycleview);
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
- Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
- return insets;
- });
- }
- }
复制代码 结果展示:
github仓库代码地址
ygy-123/android_firstapp
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |