目录

1.页面布局分析与项目结构展示

2.完成页面布局

2.1顶部页面效果

2.2底部页面效果

2.3内容页面效果

2.4综合三个页面

3.页面切换效果

3.1切换页面

3.2绑定事件

3.3定义事件

4.源代码仓库地址,实验结果,实验心得


1.页面布局分析与项目结构展示

页面布局分析:

整体思路:将整个页面划分为三个部分,顶部head,底部bottom,中间content。根据课堂所学和日常生活中使用微信的经验可知:顶部,中间都随着底部相应按钮的点击而切换到相应的页面。因此顶部,中间,底部它们之间有一层逻辑。所以中间的content部分就要有页面切换的效果,而且里面得有四个xml文件分别对应着四个页面(微信Chat,联系人People,发现Find,我的personal),使用FragmentTransaction实现。底部按钮需要实现点击一个按钮就切换一个页面而且会点亮按钮的效果,所以需要四个监听按钮,然后对监听的四个按钮绑定触发事件。

项目结构展示:

2.完成页面布局

2.1顶部页面效果

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="@color/black"android:paddingBottom="10dp"android:paddingTop="10dp"android:text="@string/vx"android:textAlignment="center"android:textColor="@color/white"android:textSize="30sp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

2.2底部页面效果

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<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:id="@+id/layout_all"android:layout_width="match_parent"android:layout_height="wrap_content"tools:ignore="MissingConstraints"><LinearLayoutandroid:id="@+id/layout1"android:layout_width="wrap_content"android:layout_height="90dp"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView1"android:layout_width="match_parent"android:layout_height="70dp"app:srcCompat="@drawable/weixin"tools:ignore="ImageContrastCheck" /><TextViewandroid:id="@+id/textView1"android:layout_width="match_parent"android:layout_height="match_parent"android:text="@string/vx"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:id="@+id/layout2"android:layout_width="wrap_content"android:layout_height="90dp"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView2"android:layout_width="match_parent"android:layout_height="70dp"app:srcCompat="@drawable/contact" /><TextViewandroid:id="@+id/textView2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/contact"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:id="@+id/layout3"android:layout_width="wrap_content"android:layout_height="90dp"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView3"android:layout_width="match_parent"android:layout_height="70dp"app:srcCompat="@drawable/find" /><TextViewandroid:id="@+id/textView3"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/find"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:id="@+id/layout4"android:layout_width="wrap_content"android:layout_height="90dp"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView4"android:layout_width="match_parent"android:layout_height="70dp"app:srcCompat="@drawable/myself" /><TextViewandroid:id="@+id/textView4"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="@string/myself"android:textAlignment="center" /></LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

2.3内容页面效果

页面视图层的实现:

微信界面(Chat):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView_chat"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="你好!这是微信页面!"android:textSize="30sp" />
</androidx.constraintlayout.widget.ConstraintLayout>

联系人界面(people):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView_chat"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="你好!这是联系人页面!"android:textSize="30sp" />
</androidx.constraintlayout.widget.ConstraintLayout>

发现界面(find):

<?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"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView_chat"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="你好!这是发现页面!"android:textSize="30sp"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

我的界面(personal):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/textView_chat"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="你好!这是我的页面!"android:textSize="30sp" />
</androidx.constraintlayout.widget.ConstraintLayout>

2.4综合三个页面

<?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"android:layout_width="match_parent"android:layout_height="match_parent"><includeandroid:id="@+id/include"layout="@layout/t1"android:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintBottom_toBottomOf="parent" /><FrameLayoutandroid:id="@+id/frameLayout"android:layout_width="0dp"android:layout_height="0dp"app:layout_constraintBottom_toTopOf="@+id/include"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/include2"></FrameLayout><includeandroid:id="@+id/include2"layout="@layout/layout_head"android:layout_width="0dp"android:layout_height="wrap_content"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>

页面的视图层完成。

3.页面切换效果

页面逻辑层的实现:对于页面切换,就是监听图片按钮,触发事件。

3.1切换页面

切换页面使用FragmentTransaction;在initFragment中使用add()方法将四个切换页面添加到FrameLayout中,然后通过show()展示对应的页面,hide()隐藏相应的页面。所以,切换效果可以通过在show()之前调用hide()隐藏所有被add()的页面实现。

3.2绑定事件

主要是setOnClickListener()方法进行监听事件。

3.3定义事件

在组件绑定好事件后,定义触发后会执行的事件。主要思路为:点击按钮后,会从view传入相应的组件,获取组件的id,由此知道是哪个按钮,然后将所有的按钮灰。再判断传入的id,切换到这个按钮对应的页面,并将这个页面按钮变亮。

package com.example.work;import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener{private Fragment fragment1,fragment2,fragment3,fragment4;private ImageView imageView1,imageView2,imageView3,imageView4;private FragmentManager manager;private FragmentTransaction transaction;private LinearLayout linearLayout1,linearLayout2,linearLayout3,linearLayout4;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);linearLayout1=findViewById(R.id.layout1);linearLayout2=findViewById(R.id.layout2);linearLayout3=findViewById(R.id.layout3);linearLayout4=findViewById(R.id.layout4);fragment1=new ChatFragment();fragment2=new PeopleFragment();fragment3=new FindFragment();fragment4=new PersonalFragment();manager=getSupportFragmentManager();initImageView();initial();hidden();linearLayout1.setOnClickListener(this);linearLayout2.setOnClickListener(this);linearLayout3.setOnClickListener(this);linearLayout4.setOnClickListener(this);}private void initial() {transaction=manager.beginTransaction().add(R.id.frameLayout,fragment1).add(R.id.frameLayout,fragment2).add(R.id.frameLayout,fragment3).add(R.id.frameLayout,fragment4);transaction.commit();}@Overridepublic void onClick(View view) {switch (view.getId()){case R.id.layout1:select(1);break;case R.id.layout2:select(2);break;case R.id.layout3:select(3);break;case R.id.layout4:select(4);break;};}private void select( int i) {TextView textView = findViewById(R.id.textView);hidden();resetImg();switch (i){case 1:showfragment(fragment1);imageView1.setImageResource(R.drawable.weixinthis);textView.setText(R.string.vx);break;case 2:showfragment(fragment2);imageView2.setImageResource(R.drawable.contactthis);textView.setText(R.string.contact);break;case 3:showfragment(fragment3);imageView3.setImageResource(R.drawable.findthis);textView.setText(R.string.find);break;case 4:showfragment(fragment4);imageView4.setImageResource(R.drawable.myselfthis);textView.setText(R.string.myself);break;}}private void showfragment(Fragment fragment) {transaction.show(fragment);}private void hidden() {transaction=manager.beginTransaction().hide(fragment1).hide(fragment2).hide(fragment3).hide(fragment4);transaction.commit();}private void initImageView() {imageView1 = findViewById(R.id.imageView1);imageView2 = findViewById(R.id.imageView2);imageView3 = findViewById(R.id.imageView3);imageView4 = findViewById(R.id.imageView4);linearLayout1 = findViewById(R.id.layout1);linearLayout2 = findViewById(R.id.layout2);linearLayout3 = findViewById(R.id.layout3);linearLayout4 = findViewById(R.id.layout4);}private void resetImg() {    //调用灰色的图片,以让点击过后的图片回复原色imageView1.setImageResource(R.drawable.weixin);imageView2.setImageResource(R.drawable.contact);imageView3.setImageResource(R.drawable.find);imageView4.setImageResource(R.drawable.myself);}}

4.源代码仓库地址,实验结果,实验心得

实验结果

视频:

work

图片:

 实验心得:

本次的实验报告我遇到了很多问题但也学到了很多,感谢肖老师和杨老师还有同学们的帮助。在做实验中遇到了很多新手问题,比如变量名写重复会导致虚拟机运行不出来页面;ID漏写会导致页面显示不出来。通过做实验明白了写代码要精益求精,一丝不苟的道理。

源代码仓库地址:https://github.com/07Echo/work

实验一 :类微信界面设计相关推荐

  1. Android Studio——类微信界面设计

    设计目标:Android studio制作简易类微信界面. 功能:展示四个可切换界面,当点击下方按钮时,界面随之切换. 布局:顶部和底部layout.主页面(中间放一个framelayout显示界面内 ...

  2. Android——类微信界面设计

    移动开发技术1 设计类微信APP门户界面,包含4个tab切换效果 1.页面分为上中下三部分:分别为标题,显示内容,切换按钮: 2.底部选择框发生改变时,中间显示内容也发生相对应的改变: 导入相关文件 ...

  3. Android Studio类微信界面设计

    文章目录 一.类微信界面能实现的功能 二.xml代码 top.xml bottom.xml tab.xml activity_main.xml 三.Java代码 MainActivity.java w ...

  4. Android开发-UI界面--类微信页面设计

    Android开发-UI界面–类微信页面设计 一.功能说明 设计一个类似微信的主页面框架,UI布局为上中下结构,包含了四个tag页面 二.开发技术 ​ 本次用到了layout.xml.控件.监听.fr ...

  5. 安卓移动开发技术--微信界面设计

    1.内容:请根据课程实现App门户界面框架设计,至少包含4个tab页,能实现tab页之间的点击切换: 2.技术:使用布局和分段,对控件进行点击监听 实现界面展示: 一.界面布局分析 1.先对butto ...

  6. 用AS实现微信界面设计

    提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 设计目标 一.结果展示 二.top.xml 三.bottom.xml 四.4个fragment.xml 五.activity ...

  7. Android studio实现类微信界面

    1.需要实现的功能: 页面具有标题微信 页面具有中间显示框 页面具有底部选择框,并且具有选择事件 页面底部选择框在进行改变的时候,我们需要中间显示框的页面同步改变 页面的布局清晰 效果展示如下 1.按 ...

  8. 实验一 基本 UI 界面设计

    实验一 基本 UI 界面设计 [实验目的] 1.熟悉 Android Studio 开发工具操作 2.熟悉 Android 基本 UI 开发,并进行 UI 基本设计 [实验内容] 实现如下 Andro ...

  9. Android Studio 类微信界面的制作

    设计目标 使用Android Studio完成类微信的门户页面框架设计,APP包含4个tab页面.框架设计使用fragment,activity. 功能说明 界面的样式和微信打开后的界面相似 1点击底 ...

最新文章

  1. python random
  2. spm oracle cloud,oracle11g新特点——SQLPlanManagement(SPM)-Oracle
  3. leetcode 241. Different Ways to Add Parentheses | 241. 为运算表达式设计优先级(Java)
  4. 如何一次性复制带有markdown/mathjax/latex的博客内容
  5. 青蛙跳台阶的问题——Fibonacci
  6. keep-alive和多路复用
  7. python-九九乘法打印
  8. mysql中status状态说明
  9. 飞翔 noip提高组难度
  10. 范数规则化(一):L0、L1与L2范数
  11. MySQL时间戳和时间的获取/相互转换/格式化
  12. 去掉dt和dd默认间隔的方法
  13. 985本科生歧视北大博导“第一学历”,“无法相信北大会有这么差的师资”
  14. mysql字符串类型的数字比较大小sql该如何写呢
  15. oracle 添加删除 某个字段,并添加注释
  16. ESP32 快速入门(九):自定义 ESP32 分区表 partitions.csv
  17. 电商直播系统_电商直播源码中购物车功能实现
  18. Neo4j Community Edition社区版本下载、安装、使用
  19. 指挥调度中心如何选择调度台?
  20. Java对List集合进行排序

热门文章

  1. c语言union(c语言union用法)
  2. 利用Python求:若一个五位数是abcde,此数乘以4之后得到edcba,求这个数
  3. 第一次使用taskctl启动遇到问题
  4. XYNUOJ1561-广告印刷
  5. MATLAB sub2ind函数用法
  6. 神经网络与深度学习(三):如何提升神经网络学习效果
  7. 留学生日常英语36~40
  8. R语言读取文件乱码的处理
  9. 杭州计算机职业学校,杭州中专职业学校排名
  10. php 哈希碰撞攻击,浅谈php的哈希碰撞