一、功能需求

完成一个类似微信页面的布局,要求:

  1. 页面最上方是标题居中
  2. 页面中间界面显示内容,内容随下方栏的选择而切换
  3. 页面最下方有四个按钮
  4. 点击按钮后,按钮图标会变换颜色,且显示框变换内容

项目大致框架如下:

二、页面布局

顶部和底部

1.head.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"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:background="@color/black"android:text="微信"android:textAlignment="center"android:textColor="@color/white"android:textSize="30sp" />
</LinearLayout>

2.bottom.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:id="@+id/layout_all"android:layout_width="match_parent"android:layout_height="wrap_content"><LinearLayoutandroid:id="@+id/layout1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/chat"android:layout_width="100dp"android:layout_height="106dp"app:srcCompat="@drawable/chat_normal"tools:ignore="ImageContrastCheck" /><TextViewandroid:id="@+id/textView1"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="微信"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:id="@+id/layout2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView2"android:layout_width="100dp"android:layout_height="106dp"app:srcCompat="@drawable/people_normal" /><TextViewandroid:id="@+id/textView2"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="联系人"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:id="@+id/layout3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView3"android:layout_width="100dp"android:layout_height="106dp"app:srcCompat="@drawable/find_normal" /><TextViewandroid:id="@+id/textView3"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="发现"android:textAlignment="center" /></LinearLayout><LinearLayoutandroid:id="@+id/layout4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView4"android:layout_width="100dp"android:layout_height="104dp"app:srcCompat="@drawable/personal_normal" /><TextViewandroid:id="@+id/textView4"android:layout_width="122dp"android:layout_height="wrap_content"android:text="我的"android:textAlignment="center" /></LinearLayout>
</LinearLayout>

效果如下:

三、四个内容区

fragment 和xml  ,下面用的是chat为例

package com.example.wechat;
import android.view.LayoutInflater;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;import androidx.fragment.app.Fragment;public class chatfragment extends Fragment {public chatfragment(){}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.chat, container, false);}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/fragment_chat"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".chatfragment"><!-- TODO: Update blank fragment layout --><TextViewandroid:id="@+id/textView_chat"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="聊天界面"android:textSize="30sp" /></LinearLayout>

四、编写main 的activity和xml

package com.example.wechat;import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity implements View.OnClickListener {private FragmentManager fm = getSupportFragmentManager();private LinearLayout linearLayout1, linearLayout2, linearLayout3, linearLayout4;private ImageView imageView1,imageView2,imageView3,imageView4;private Fragment chatfragment = new chatfragment();private Fragment peoplefragment = new peoplefragment();private Fragment findfragment = new findfragment();private Fragment personalFragment = new personfragment();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initFragment();initImageView();showFragment(0);linearLayout1.setOnClickListener(this);linearLayout2.setOnClickListener(this);linearLayout3.setOnClickListener(this);linearLayout4.setOnClickListener(this);}private void initFragment() {FragmentTransaction transaction = fm.beginTransaction();transaction.add(R.id.fragment_content, chatfragment);transaction.add(R.id.fragment_content, peoplefragment);transaction.add(R.id.fragment_content, findfragment);transaction.add(R.id.fragment_content, personalFragment);transaction.commit();}private void initImageView() {imageView1 = findViewById(R.id.chat);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 hideFragment(FragmentTransaction transaction) {transaction.hide(chatfragment);transaction.hide(personalFragment);transaction.hide(findfragment);transaction.hide(personalFragment);}@Overridepublic void onClick(View view) {FragmentTransaction fragmentTransaction = fm.beginTransaction();hideFragment(fragmentTransaction);resetImg();switch (view.getId()) {case R.id.layout1:showFragment(0);break;case R.id.layout2:showFragment(1);break;case R.id.layout3:showFragment(2);break;case R.id.layout4:showFragment(3);break;default:break;}}private void resetImg() {    //调用灰色的图片,以让点击过后的图片回复原色imageView1.setImageResource(R.drawable.chat_normal);imageView2.setImageResource(R.drawable.people_normal);imageView3.setImageResource(R.drawable.find_normal);imageView4.setImageResource(R.drawable.personal_normal);}private void showFragment(int i) {    //控制图片颜色的变换,其意义是点击一个图片之后该图片就会变亮FragmentTransaction transaction = fm.beginTransaction();hideFragment(transaction);switch (i) {case 0:transaction.show(chatfragment);imageView1.setImageResource(R.drawable.chat_active);break;case 1:transaction.show(peoplefragment);imageView2.setImageResource(R.drawable.people_active);break;case 2:transaction.show(findfragment);imageView3.setImageResource(R.drawable.find_active);break;case 3:transaction.show(personalFragment);imageView4.setImageResource(R.drawable.personal_active);break;default:break;}transaction.commit();}
}
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"tools:context=".MainActivity"><include layout="@layout/head" /><FrameLayoutandroid:id="@+id/fragment_content"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"></FrameLayout><include layout="@layout/bottom"android:gravity="bottom"/>
</LinearLayout>

最终的效果

gitee仓库地址

wechat 界面 · 935be06 · 吉吉的耳朵不太好/Wechat - Gitee.com

安卓开发之设计微信界面相关推荐

  1. 安卓移动开发实验:Android Studio设计微信界面

    一.实验的目的 通过使用Android Studio的Fragment和layout,来实现简单的微信界面切换. 二.app的功能 能够通过应用底部的bottom来实现四个页面的来回切换. 三.实验过 ...

  2. 安卓开发Java版——UI界面的设计

    UI界面设计 常见控件使用方法 TextView android:background 背景颜色 android:layout_width和android:layout_height指定了控件的宽度和 ...

  3. 安卓开发之集成微信登录以及分享群聊,朋友圈功能。

    准备工作 先申请应用的各种ID,官网地址:https://open.weixin.qq.com 集成 添加依赖. implementation 'com.tencent.mm.opensdk:wech ...

  4. 安卓开发_自定义控件_界面的简单侧滑

    主界面 package com.itheima.news;import android.os.Bundle; import android.app.Activity; import android.v ...

  5. 安卓开发淘宝抢购界面!史上最全的Android面试题集锦,附带学习经验

    前言 这是"拔剑金九银十"的第二篇文章,本文主要针对3年以上的Android开发者进阶面试中高级开发工程师而整理. 希望可以对你们有所帮助.不多废话,进入正题. 目录: Java中 ...

  6. Android安卓开发集成微信第三方扫描二维码登录-超级无敌具详细

    Android安卓开发中集成微信二维码登录的步骤: 写在前面的: 该教程使用AS作为演示,使用ecplise请参照微信官方文档下载相应jar等所需参考文档和资源.在最后,我会附上这个Activity的 ...

  7. android 多界面开发,安卓开发教程(Android多界面应用程序开发)

    安卓开发教程(Android多界面应用程序开发) 开篇 本文阅读需10分钟,简单易上手,属于安卓开发教程的基础部分. 建议精读,深刻理解大意.多做实践.多写代码. 本文章由做全栈攻城狮原创首发. 同名 ...

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

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

  9. 安卓开发 微信ui界面设计 (Android Studio)

    功能: 开发一个类似微信的主页面框架,UI布局为上中下结构,包含4个tab界面: 开发技术为: layout xml.控件.监听,fragment: 设计流程: 创建项目 改下项目名,编程语言为jav ...

最新文章

  1. 2019研究生新生大数据出炉!清华园迎来8900多名新主人
  2. 手机自动化测试:Appium源码分析之跟踪代码分析四 1
  3. 基于AngularJS的Onsen UI --Onsen UI学习笔记
  4. 工作单元php,PHP面向对象之工作单元
  5. TF之data_format:data_format中的NHWCNCHW简介、转换的详细攻略
  6. leetcode 27. 移除元素(双指针)
  7. 【MySQL】MySQL监视器无法启动的可能情况
  8. shell学习脚本-tomcat停止脚本
  9. BGP的community属性
  10. 05-Vue报错 Uncaught SyntaxError: Identifier has already been declared和路由
  11. 看漫画学python 电子书_看漫画学Python电子版(mobi azw3 epub)
  12. Linux 并发测试工具 httpd-tools工具的安装和使用
  13. 内测体验:JetBrains面向未来的Fleet编辑器是什么+究竟怎样 使用初体验+与vsc对比
  14. Scrum板与Kanban如何抉择?敏捷工具:SHSYdsjgyadtgad
  15. 计算机网络教程(第四版)
  16. 我遇到了bug,请问该如何解决
  17. 安装mysql5.7防火墙关了为什么远程登录不了呢?
  18. Qt的.pro工程文件语法学习
  19. Qt官方示例:Fridge Magnets Example(冰箱贴)
  20. CodeBlocks+wxWidgets

热门文章

  1. PAT --- 1036.跟奥巴马一起编程 (15 分)
  2. 利用go制作微信机器人
  3. 【洛谷3110】【USACO14DEC】驮运Piggy Back
  4. Labview中数据类型转换
  5. JS入门到入土之数字运算符扩展
  6. c语言按字母排序用直接插入法,直接插入排序(C语言实现)
  7. TOJ 4074 Running Laps -- 树状数组
  8. 能独步天下吗?揭开至强E5处理器的最后面纱
  9. 作为站长,给火绒吹一次,论杀毒谁强?
  10. 百度地图API--信息窗口