先看一下效果图
就是这样,其实不难,只要布局多了点,MainActivity里的代码很少,只要布局整好了,那么这个搜索界面很快就会实现。
我标红的这两行代码,使用的include方法,可以得到别的布局,添加到主布局文件中,大家可以试一下。
我先展示一下我的布局:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context=".MainActivity">
<include layout="@layout/horizontal_item"/>
<include layout="@layout/horizontal_item_one"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp">
<com.example.library.AutoFlowLayout
android:id="@+id/auto_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></com.example.library.AutoFlowLayout>
<RelativeLayout
android:id="@+id/re1"
android:layout_below="@id/auto_layout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="35dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索发现"
android:textStyle="bold"
android:layout_marginTop="6dp"
android:layout_marginLeft="5dp"
android:textSize="16dp"/>
<TextView
android:layout_marginTop="40dp"
android:layout_marginLeft="8dp"
android:layout_width="75dp"
android:paddingTop="4dp"
android:gravity="center_horizontal"
android:layout_height="35dp"
android:textSize="17d