由于最新项目需要实现一个搜索功能,需求是和ios的样式相同,ios有第三方库直接引用就可以使用,而android这边全是md风格的,并不是我想要的,所以只能自己写了,如果有时间一定封装成库。首先看下效果图
首先看下需要用到的东西,1,首页搜索是一个TextView自不必说,主要是热门搜索的流式布局,但是今天的主角不是它,如果不太懂的朋友可以移步这里:[Android中常见的流式布局的使用 ](http://blog.csdn.net/sinat_36668731/article/details/53198172),2.就是历史搜索,这里需要用到数据库的一些知识,我会在后面具体说明。首先看下xml代码,非常的简单:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="92px"
android:gravity="center_vertical"
android:focusable="true"
android:padding="6px"
android:background="@color/colorTextGroupBg"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<EditText
android:id="@+id/et_search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_margin="6px"
android:layout_weight="1"
android:background="@drawable/edit_text_bg"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint=" 请输入要搜索的关键词"
android:paddingBottom="10px"
android:paddingLeft="30px"
android:paddingTop="10px"
android:textColor="#333"
android:textColorHint=