IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> 类微信的门户页面框架设计 -> 正文阅读

[移动开发]类微信的门户页面框架设计

一、设计目标

根据课程教学内容完成类微信的门户页面框架设计,APP最少必须包含4个tab页面。框架设计需要使用fragment,activity,不得使用UNIAPP技术进行开发(H5或者小程序)。

二、功能说明

图片的顶端是一个LinearLayout,它包含了一个TextVeiw文本框,用于显示软件名“xx”。

图片的中间是APP的四个tab页面,每个tab页面都是使用Fragment实现了activity与tab对应的页面分离,通过点击tab来切换页面,每个页面都有自己单独的文本显示内容。

图片的底端是由一些LinearLayout组合而成的导航栏,它显示的是四个主要功能和相对应的功能图标,当点击相对应的图标或者文字的时候,文字和图标会高亮显示提示你点击了某个相关的功能,当你点击另外的功能时,高亮也会随之刷新。

三、代码解析

1.顶部layout_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="70dp"
    android:background="#D3D3D3">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="xx"
        android:textSize="30sp" />

</LinearLayout>

2.底部layout_bottom.xml?

底部导航栏的实现主要是依靠多个LinearLayout组合而成的,首先是在底端放置了一个水平的LinearLayout,然后在其中放置四个垂直的LinearLayout,每个垂直的LinearLayout用于存放对应的文字TextView与图标ImageView。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="#D3D3D3"
    android:gravity="center">

    <LinearLayout
        android:id="@+id/chat"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:srcCompat="@drawable/chat" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="消息"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/contact"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:srcCompat="@drawable/contact" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="通讯录"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/find"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:srcCompat="@drawable/find" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="发现"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/me"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:srcCompat="@drawable/me" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="我 "
            android:textSize="20sp" />
    </LinearLayout>
</LinearLayout>

3.四个页面的Fragment.xml?(仅展示其一,其余与其类似)

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:gravity="center"
        android:text="消息界面"
        android:textSize="25sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

4.activity_main.xml?

?在其中include顶部与底部的xml文件名。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<include layout="@layout/layout_top"></include>
    
<FrameLayout
    android:id="@+id/frame_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"></FrameLayout>


<include layout="@layout/layout_bottom"></include>
    
</LinearLayout>

5.Fragment_chat.java(仅展示其一,其余与其类似)

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;

public class Fragment_chat extends Fragment {

    public Fragment_chat() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.layout_chat,container,false);
    }
}

6.MainActivity.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private Fragment fragment_first=new Fragment_chat();
    private Fragment fragment_second=new Fragment_contact();
    private Fragment fragment_third=new Fragment_find();
    private Fragment fragment_fourth=new Fragment_me();

    private FragmentManager fragmentManager;

    private LinearLayout linear_first;
    private LinearLayout linear_second;
    private LinearLayout linear_third;
    private LinearLayout linear_fourth;

    private ImageView imageView_first;
    private ImageView imageView_second;
    private ImageView imageView_third;
    private ImageView imageView_fourth;

    private TextView textView_first;
    private TextView textView_second;
    private TextView textView_third;
    private TextView textView_fourth;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE );
        setContentView(R.layout.activity_main);

        initView();
        initFragment();
        initEvent();

        selectFragment(0);
        imageView_first.setColorFilter(Color.CYAN);
        textView_first.setTextColor(Color.CYAN);
    }

    @Override
    public void onClick(View view) {
        restartButton();

        switch(view.getId())
        {
            case R.id.chat:
                selectFragment(0);
                imageView_first.setColorFilter(Color.CYAN);
                textView_first.setTextColor(Color.CYAN);
                break;
            case R.id.contact:
                selectFragment(1);
                imageView_second.setColorFilter(Color.CYAN);
                textView_second.setTextColor(Color.CYAN);
                break;
            case R.id.find:
                selectFragment(2);
                imageView_third.setColorFilter(Color.CYAN);
                textView_third.setTextColor(Color.CYAN);
                break;
            case R.id.me:
                selectFragment(3);
                imageView_fourth.setColorFilter(Color.CYAN);
                textView_fourth.setTextColor(Color.CYAN);
                break;
            default:
                break;
        }
    }
    private void restartButton() {
        imageView_first.setColorFilter(0);
        textView_first.setTextColor(Color.GRAY);
        imageView_second.setColorFilter(0);
        textView_second.setTextColor(Color.GRAY);
        imageView_third.setColorFilter(0);
        textView_third.setTextColor(Color.GRAY);
        imageView_fourth.setColorFilter(0);
        textView_fourth.setTextColor(Color.GRAY);
    }
    private void initFragment(){
        fragmentManager=getSupportFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        transaction.add(R.id.frame_content,fragment_first);
        transaction.add(R.id.frame_content,fragment_second);
        transaction.add(R.id.frame_content,fragment_third);
        transaction.add(R.id.frame_content,fragment_fourth);
        transaction.commit();
    }

    private  void initView(){
        linear_first=findViewById(R.id.chat);
        linear_second=findViewById(R.id.contact);
        linear_third=findViewById(R.id.find);
        linear_fourth=findViewById(R.id.me);

        imageView_first=findViewById(R.id.imageView1);
        imageView_second=findViewById(R.id.imageView2);
        imageView_third=findViewById(R.id.imageView3);
        imageView_fourth=findViewById(R.id.imageView4);

        textView_first=findViewById(R.id.textView1);
        textView_second=findViewById(R.id.textView2);
        textView_third=findViewById(R.id.textView3);
        textView_fourth=findViewById(R.id.textView4);

    }
    private void initEvent(){
        linear_first.setOnClickListener(this);
        linear_second.setOnClickListener(this);
        linear_third.setOnClickListener(this);
        linear_fourth.setOnClickListener(this);
    }
    private void hideView(FragmentTransaction transaction){
        transaction.hide(fragment_first);
        transaction.hide(fragment_second);
        transaction.hide(fragment_third);
        transaction.hide(fragment_fourth);
    }
    private void selectFragment(int i){
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        hideView(transaction);
        switch (i){
            case 0:
                transaction.show(fragment_first);

                break;
            case 1:
                transaction.show(fragment_second);

                break;
            case 2:
                transaction.show(fragment_third);

                break;
            case 3:
                transaction.show(fragment_fourth);

                break;
            default:
                break;
        }
        transaction.commit();
    }

}

四、运行展示截图

五、源码仓库地址

GitHub - banyue2020/My_Application

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-10-08 20:53:18  更:2022-10-08 20:56:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/20 0:31:07-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码