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

看到是这个界面我们首先应该思考这些按钮是怎么做出来的?有了一个整体的思路之后才知道该怎么办。最开始我想的就直接利用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"> <TextView
android:id="@+id/top_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="发现"
android:textSize="15sp"
/> <ImageView
android: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"
/> <ImageView
android: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"> <include
layout="@layout/view_yop"
android:id="@+id/great"
>
</include>
<LinearLayout
android: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">
<ImageView
android:layout_gravity="center"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/pengyou"/>
<TextView
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="朋友圈"/> </LinearLayout>
<include
layout="@layout/saoyisao"
android:id="@+id/great"
> </include>
<TextView
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#C0C0C0"/>
<LinearLayout
android: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">
<ImageView
android:layout_gravity="center"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/yaoyi"/>
<TextView
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="摇一摇"/> </LinearLayout> <TextView
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#C0C0C0"/> <include layout="@layout/kanyikan" > </include> <LinearLayout
android: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">
<ImageView
android:layout_gravity="center"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/souyisou"/>
<TextView
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜一搜"/> </LinearLayout>
<LinearLayout
android: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">
<ImageView
android:layout_gravity="center"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/fujin"/>
<TextView
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="附近的人"/> </LinearLayout> <include
layout="@layout/gouwu" > </include>
<TextView
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#C0C0C0"/>
<LinearLayout
android: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">
<ImageView
android:layout_gravity="center"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/youxi"/>
<TextView
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游戏"/> </LinearLayout> <LinearLayout
android: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">
<ImageView
android:layout_gravity="center"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/xiaochengxu"/>
<TextView
android: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">
<ImageView
android:id="@+id/top_r"
android:layout_width="17dp"
android:layout_height="17dp"
android:src="@drawable/gouwu"
android:layout_centerVertical="true" />
<TextView
android: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">
<ImageView
android:id="@+id/top_r"
android:layout_width="17dp"
android:layout_height="17dp"
android:src="@drawable/kanyikan"
android:layout_centerVertical="true" />
<TextView
android: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">
<ImageView
android:id="@+id/top_r"
android:layout_width="17dp"
android:layout_height="17dp"
android:src="@drawable/saoyisao"
android:layout_centerVertical="true" />
<TextView
android: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. 安卓开发笔记(十三):SQLite数据库储存(下)数据的增添,更改,删除,查询

      SQLite数据库存储(下) 1.增添数据 对于添加数据的话我们只需要在主活动当中import新的包以及在主活动当中写上适当的代码就可以了,不需要在我们之前创建新的类当中书写新的代码.现在的主活动 ...

  2. 安卓开发笔记——ViewPager组件(仿微信引导界面)

    这2天事情比较多,都没时间更新博客,趁周末,继续继续~ 今天来讲个比较新潮的组件——ViewPager 什么是ViewPager? ViewPager是安卓3.0之后提供的新特性,继承自ViewGro ...

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

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

  4. 安卓开发笔记——关于开源项目SlidingMenu的使用介绍(仿QQ5.0侧滑菜单)

    记得去年年末的时候写过这个侧滑效果,当时是利用自定义HorizontalScrollView来实现的,效果如下: 有兴趣的朋友可以看看这篇文件<安卓开发笔记——自定义HorizontalScro ...

  5. 安卓开发笔记——深入Activity

    在上一篇文章<安卓开发笔记——重识Activity >中,我们了解了Activity生命周期的执行顺序和一些基本的数据保存操作,但如果只知道这些是对于我们的开发需求来说是远远不够的,今天我 ...

  6. 安卓开发笔记——丰富多彩的TextView

    随手笔记,记录一些东西~ 记得之前写过一篇文章<安卓开发笔记——个性化TextView(新浪微博)>:http://www.cnblogs.com/lichenwei/p/4411607. ...

  7. 安卓开发笔记——打造万能适配器(Adapter)

    为什么要打造万能适配器? 在安卓开发中,用到ListView和GridView的地方实在是太多了,系统默认给我们提供的适配器(ArrayAdapter,SimpleAdapter)经常不能满足我们的需 ...

  8. 安卓开发_浅谈Android动画(四)

    Property动画 概念:属性动画,即通过改变对象属性的动画. 特点:属性动画真正改变了一个UI控件,包括其事件触发焦点的位置 一.重要的动画类及属性值: 1.  ValueAnimator 基本属 ...

  9. 安卓开发笔记——关于Handler的一些总结(上)

    接上篇文章<安卓开发笔记——关于AsyncTask的使用>,今天来讲下在安卓开发里"重中之重"的另一个异步操作类Handler. 今天打算先讲下关于Handler的一些 ...

随机推荐

  1. Asp.Net Core 内置IOC容器的理解

    Asp.Net Core 内置IOC容器的理解 01.使用IOC容器的好处 对接口和实现类由原来的零散式管理,到现在的集中式管理. 对类和接口之间的关系,有多种注入模式(构造函数注入.属性注入等). ...

  2. windows 下安装beego

    好久没写博客了,最近忙于一些杂事,看见有几个博友留言了,未能及时回复,稍后晚点回复诸位博友.不多说了,windows安装beego(请先确保git环境已安装并设置了git环境变量.这个简单网上很多教程 ...

  3. Change Field Layout and Visibility in a List View 在列表视图中更改字段布局和可见性

    This lesson will guide you through the steps needed to select columns displayed in the List View. Fo ...

  4. Implement Dependent Reference Properties 实现从属引用属性 (XPO)

    In this lesson, you will learn how to implement properties whose values can depend on other properti ...

  5. CSS学习笔记-2D转换模块

    2D转换模块:    1.旋转        1.1格式:            transform:rotate(45deg);        1.2含义:            表示旋转多少度   ...

  6. 038.[转] JVM启动过程与类加载

    From: https://blog.csdn.net/luanlouis/article/details/40043991 Step 1.根据JVM内存配置要求,为JVM申请特定大小的内存空间 ? ...

  7. 渗透测试学习 二十九、kali安装,信息搜集,服务器扫描

    kali安装,信息搜集,服务器扫描 kali介绍 Kali Linux是基于Debian的Linux发行版, 设计用于数字取证操作系统.由Offensive Security Ltd维护和资助.最先由 ...

  8. CodeForces 862B(思维+二分图染色)

    题意 https://vjudge.net/problem/CodeForces-862B 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 思路 因为题目是求的最多添加多少边,所以可 ...

  9. 搭建 Optix 环境

    我参考了 第0个示例 OptixHello 学习Optix的工程配置以及基本框架 的配置过程,该文对于 Optix 的框架介绍的很好,但是按照该文配置遇到了一些问题,我花费了一番功夫自己摸索终于配置好 ...

  10. Python模块import本质是什么?import是什么

    ​ 写这篇文章主要是对Python的import模块或包的机制有了更深层级的一个理解,也在具体工作中得到了一点实践,这种思考是由上一篇文章<__main__内置模块预加载Shotgun接口的妙用 ...