首先我们来看看仿写之后的效果:

看到是这个界面我们首先应该思考这些按钮是怎么做出来的?有了一个整体的思路之后才知道该怎么办。最开始我想的就直接利用button控件上面直接加上png的图片就可以形成一个按钮了,但当我加入图片之后,发现因为图片太大导致一个按钮都会占据一个屏幕一半的空间,实在是得不偿失,根本无法使用。如果直接利用button在上面添加图片,是不能够改变我们加入图片的大小的,虽然这是最简单的方法,但是缺陷比较多,如果实在先使用这种方法就必须自己将png图片的大小变小,但作为一个程序员还是算了。之后我又想到了自定义view,但是这个方法太麻烦了,对Java的要求较高,因此才考虑到了这里的第三种方法:将每一个按钮写成一个linearlayout,并将每一个线性布局设定成可以被监听的模式,这样就可以完全当一个按钮来使用了,还可以为它设定选择器,也就是我们的selector,最后的效果和我们的button一样,点击之后也会发生颜色的改变(白色变成灰色)。

  我们仔细观察,每两个按钮之间还会有一条很细的线,这条线则直接可以使用textview控件来进行填充、利用backgroud属性就可以设定textview的背景颜色,里面没有文字也没有任何关系,但是需要将textview的高度设定成0.5或者1dp。这样大体的思路就有了,还需要注意一点的是我们在进行UI布局的时候尽可能利用include进行布局,这样才会让其他程序员能够很好地进行理解。下面我们分别来看看include的布局以及我们的主界面的布局。

一.首页标题栏

首页标题栏我就直接使用了一个相对布局,后面引用两个imageview,为了效果的展示。如果真要将这两个图标设定为可以监听的话,可以直接将这个控件更改为imagebutton,并给它设定一个响应的id即可。不需要做过多的修改。这个布局我们会通过include直接引入到我们的主界面当中。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="60dp"android:orientation="vertical"android:background="#C0C0C0"android:padding="10dp"><TextViewandroid:id="@+id/top_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:text="发现"android:textSize="15sp"/><ImageViewandroid:layout_alignParentBottom="true"android:id="@+id/top_r"android:layout_width="17dp"android:layout_height="17dp"android:src="@drawable/sousuo"android:layout_centerVertical="true"android:layout_toLeftOf="@+id/top_left"android:layout_marginRight="29dp"/><ImageViewandroid:layout_alignParentBottom="true"android:id="@+id/top_left"android:layout_width="17dp"android:layout_height="17dp"android:src="@drawable/tianjia"android:layout_centerVertical="true"android:layout_alignParentRight="true"/></RelativeLayout>

二.主界面代码

这部分代码你就可以清晰地看到我的思路了,凡是每两个连在一起的控件的第一个自定义的按钮,我都使用了引入布局的方式,第二个按钮则直接写在了主界面之上。具体原因是因为只有第一个按钮为引入,而不是在主界面上直接编写,这样两个按钮才会连在一起,不然就会分开,达不到仿写的效果。如果您有更好的办法来解决这个问题的话,本人感激不尽。

<?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:orientation="vertical"android:background="#C0C0C0"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><includelayout="@layout/view_yop"android:id="@+id/great"></include><LinearLayoutandroid:background="#ffffff"android:id="@+id/gj_recruit"android:layout_width="match_parent"android:layout_height="50dip"android:layout_marginBottom="17dip"android:focusableInTouchMode="true"android:clickable="true"android:orientation="horizontal"android:padding="7dip"><ImageViewandroid:layout_gravity="center"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/pengyou"/><TextViewandroid:textSize="15sp"android:layout_marginLeft="10dp"android:layout_gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="朋友圈"/></LinearLayout><includelayout="@layout/saoyisao"android:id="@+id/great"></include><TextViewandroid:layout_width="match_parent"android:layout_height="0.5dp"android:background="#C0C0C0"/><LinearLayoutandroid:background="#ffffff"android:id="@+id/gj_recruit2"android:layout_width="match_parent"android:layout_height="50dip"android:layout_marginBottom="17dip"android:focusableInTouchMode="true"android:clickable="true"android:orientation="horizontal"android:padding="7dip"><ImageViewandroid:layout_gravity="center"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/yaoyi"/><TextViewandroid:textSize="15sp"android:layout_marginLeft="10dp"android:layout_gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="摇一摇"/></LinearLayout><TextViewandroid:layout_width="match_parent"android:layout_height="0.5dp"android:background="#C0C0C0"/><include layout="@layout/kanyikan"></include><LinearLayoutandroid:background="#ffffff"android:id="@+id/gj_recruit3"android:layout_width="match_parent"android:layout_height="50dip"android:layout_marginBottom="17dip"android:focusableInTouchMode="true"android:clickable="true"android:orientation="horizontal"android:padding="7dip"><ImageViewandroid:layout_gravity="center"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/souyisou"/><TextViewandroid:textSize="15sp"android:layout_marginLeft="10dp"android:layout_gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="搜一搜"/></LinearLayout><LinearLayoutandroid:background="#ffffff"android:id="@+id/gj_recruit4"android:layout_width="match_parent"android:layout_height="50dip"android:layout_marginBottom="17dip"android:focusableInTouchMode="true"android:clickable="true"android:orientation="horizontal"android:padding="7dip"><ImageViewandroid:layout_gravity="center"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/fujin"/><TextViewandroid:textSize="15sp"android:layout_marginLeft="10dp"android:layout_gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="附近的人"/></LinearLayout><includelayout="@layout/gouwu"></include><TextViewandroid:layout_width="match_parent"android:layout_height="0.5dp"android:background="#C0C0C0"/><LinearLayoutandroid:background="#ffffff"android:id="@+id/gj_recruit5"android:layout_width="match_parent"android:layout_height="50dip"android:layout_marginBottom="17dip"android:focusableInTouchMode="true"android:clickable="true"android:orientation="horizontal"android:padding="7dip"><ImageViewandroid:layout_gravity="center"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/youxi"/><TextViewandroid:textSize="15sp"android:layout_marginLeft="10dp"android:layout_gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="游戏"/></LinearLayout><LinearLayoutandroid:background="#ffffff"android:id="@+id/gj_recruit9"android:layout_width="match_parent"android:layout_height="50dip"android:layout_marginBottom="17dip"android:focusableInTouchMode="true"android:clickable="true"android:orientation="horizontal"android:padding="7dip"><ImageViewandroid:layout_gravity="center"android:layout_width="20dp"android:layout_height="20dp"android:background="@drawable/xiaochengxu"/><TextViewandroid:textSize="15sp"android:layout_marginLeft="10dp"android:layout_gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="小程序"/></LinearLayout></LinearLayout>

我们可以清晰地看到这个项目所include的id组件有哪些,下面我们就分别展示下各个id所对应引入的布局。

三.gouwu.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/kan"android:layout_width="match_parent"android:layout_height="45dp"android:orientation="vertical"android:background="#ffffff"android:padding="10dp"><ImageViewandroid:id="@+id/top_r"android:layout_width="17dp"android:layout_height="17dp"android:src="@drawable/gouwu"android:layout_centerVertical="true"/><TextViewandroid:id="@+id/top_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@+id/top_r"android:layout_marginLeft="10dp"android:text="购物"android:textSize="15sp"/></RelativeLayout>

四.kanyikan.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/kan"android:layout_width="match_parent"android:layout_height="45dp"android:orientation="vertical"android:background="#ffffff"android:padding="10dp"><ImageViewandroid:id="@+id/top_r"android:layout_width="17dp"android:layout_height="17dp"android:src="@drawable/kanyikan"android:layout_centerVertical="true"/><TextViewandroid:id="@+id/top_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@+id/top_r"android:layout_marginLeft="10dp"android:text="看一看"android:textSize="15sp"/></RelativeLayout>

五.saoyisao.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/saoa"android:layout_width="match_parent"android:layout_height="45dp"android:orientation="vertical"android:background="#ffffff"android:padding="10dp"><ImageViewandroid:id="@+id/top_r"android:layout_width="17dp"android:layout_height="17dp"android:src="@drawable/saoyisao"android:layout_centerVertical="true"/><TextViewandroid:id="@+id/top_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@+id/top_r"android:layout_marginLeft="10dp"android:text="扫一扫"android:textSize="15sp"/>
</RelativeLayout>

这样我们的界面编写总算是完成了,唯一博客里没有讲的就是这些png图片哪里来的了,如果大家对这个很感兴趣的话,可以在这篇博文当中看看那些png图片是怎么来的。

https://www.cnblogs.com/geeksongs/p/10769365.html

如果您有更好的方法,也可以找我聊聊

安卓开发笔记(三十三):Android仿写微信发现相关推荐

  1. 【Visual C++】游戏开发笔记三十三 浅墨DirectX提高班之二 化腐朽为神奇:DirectX初始化四步曲

    这篇文章里,我们将迈出精通DirectX的第一步,先了解典型Direct3D程序的书写流程,然后学习COM接口的对象的一些思想,然后按照"四步曲"的思路,系统地学习DirectX的 ...

  2. 【Visual C++】游戏开发笔记三十三 浅墨DirectX提高班之二 化腐朽为神奇:DirectX初始化四步曲...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/zhmxy555/article/details/8197792 作者:毛星云(浅墨) ...

  3. 【Visual C++】游戏开发笔记三十三 浅墨DirectX提高班之二 化腐朽为神奇 DirectX初始化四步曲

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:  http://blog.csdn.net/zhmxy555/article/details/8197792 作者:毛星云(浅 ...

  4. 安卓开发笔记——自定义广告轮播Banner(实现无限循环)

    关于广告轮播,大家肯定不会陌生,它在现手机市场各大APP出现的频率极高,它的优点在于"不占屏",可以仅用小小的固定空位来展示几个甚至几十个广告条,而且动态效果很好,具有很好的用户& ...

  5. [安卓开发笔记二]android Studio通过jni调用C++代码

    [安卓开发笔记二]android Studio通过jni调用C++代码 16/12/11 更新 此博客基于安卓android studio 1.5所写,现在已经有了android studio2.2的 ...

  6. [安卓开发笔记一]Android开发配置opencv环境超详细教程

    [安卓开发笔记一]Android开发配置opencv环境超详细教程 [更新于 2022年4月] 再次提醒,建议现在看到这篇文章的,仅仅把此文做一个流程参考,4年前android studio就使用cm ...

  7. 安卓开发笔记——打造属于自己的博客园APP(一)

    最近事情比较多,博客更新又落下了,平时有个习惯,喜欢睡前看看博客园里博友的文章,但一直感觉APP市场上下载下来的博客园客户端用起来并不是很舒服,近来发现博客园也有对外开放的数据接口,所以打算自己写个博 ...

  8. 【Visual C++】游戏开发笔记三十七 浅墨DirectX提高班之五 顶点缓存的红颜知己 索引缓存的故事

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 本系列文 ...

  9. 【Visual C++】游戏开发笔记三十七 浅墨DirectX提高班之五 顶点缓存的红颜知己:索引缓存的故事

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接: http://blog.csdn.net/zhmxy555/article/details/8304741 作者:毛星云(浅墨 ...

最新文章

  1. 利用Spring的Aop实现项目的日志监控
  2. android 实现显示电量,Android开发:显示电池电量
  3. python脚本怎么打印日志_python 接口测试1 --如何创建和打印日志文件
  4. Loopback測试软件AX1用户手冊 V3.1
  5. 拯救者linux无法正常关机,菜鸟求助。centos无法关机。请各位高手帮忙! - Linux论坛 - 51CTO技术论坛_中国领先的IT技术社区...
  6. pandas将某列复制到另一个表_使用pandas将列从一个数据帧复制到另一个数据帧的最快方法?...
  7. pylot网站压力测试
  8. html实现飞机小游戏(源码)
  9. Windows下linux传盘工具,Windows下安装红旗Linux及工具盘全过程
  10. linux上传下载覆盖文件的命令
  11. 为什么程序员 996 会猝死,而老板 007 却不会?
  12. 指数基金投资指南——阅读笔记
  13. usr目录linux,linux系统/usr目录的意义与内容
  14. 雨季车辆天窗漏水解决银弹
  15. MATLAB编写用户登陆界面小结——更改界面左上角图标、输入用户名提醒和输入密码隐藏
  16. ArcEngine连接地理数据库(20190702)
  17. 系统调用(Linux)
  18. win10系统如何开启telnet
  19. 爱普生连续供墨系统故障排除方法
  20. 大学生计算机面试,大学生计算机毕业面试自我介绍

热门文章

  1. 工程师在美国为何成职场上的香饽饽(转自新浪乔磊)
  2. 2016百度沸点榜单出炉 看看年度搜索报告有哪些
  3. 【毕业设计】协同过滤商品推荐系统 - python 深度学习
  4. Mail::Sender
  5. windows中ip地址存放的位置,及修改
  6. 分子偶极矩大小如何判断_怎么判断分子极性大小??
  7. Linux根目录”/“下各个系统文件夹的含义和用途
  8. 老菜鸟学PYthon - 高考志愿填报数据的实时采集
  9. 20行Python代码,轻轻松松获取各路书本,你还在花钱买着看嘛~
  10. [高通SDM450][Android9.0]双屏异显、双屏异触