public class MainActivity extends AppCompatActivity {
private ImageView ssfh;
private EditText sssr;
private TextView ssss;
private AutoFlowLayout mFlowLayout;
private LayoutInflater mLayoutInflater;
private String[] mData = {"英雄联盟职业赛","帝师","全民吃鸡贺岁杯","绝地求生","王者荣耀","小智","小莫","是小银呀","察萝莉","英雄联盟","隔壁老王","DNF","穿越火线"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ssfh=findViewById(R.id.ss_fh);
sssr=findViewById(R.id.ss_sr);
ssss=findViewById(R.id.ss_ss);
mFlowLayout=findViewById(R.id.afl_cotent);
mLayoutInflater = LayoutInflater.from(this);
for (int i = 0; i< 10; i ++ ){
View item =View.inflate(this,R.layout.sub_item, null);
TextView tvAttrTag =item.findViewById(R.id.tv_attr_tag);
tvAttrTag.setText(mData[i]);
mFlowLayout.addView(item);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
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="com.example.administrator.liushibuju.MainActivity">
<LinearLayout
android:background="#FFF2F1F1"
android:orientation="horizontal"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="80dp">
<ImageView
android:id="@+id/ss_fh"
android:layout_weight="1"
android:src="@mipmap/sobot_webview_toolsbar_back_disable"
android:layout_width="wrap_content"
android:layout_height="50dp" />
<ImageView
android:src="@mipmap/icon_search"
android:layout_width="30dp"
android:layout_height="30dp" />
<EditText
android:id="@+id/ss_sr"
android:layout_weight="3"
android:hint="2018LPL英雄联盟"
android:layout_width="wrap_content"
android:layout_height="50dp" />
<TextView
android:id="@+id/ss_ss"
android:layout_weight="1"
android:text="搜索"
android:textSize="20dp"
android:gravity="center"
android:textColor="#f00"
android:layout_width="wrap_content"
android:layout_height="50dp" />
</LinearLayout>
<TextView
android:text="热门搜索"
android:textSize="17sp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.example.library.AutoFlowLayout
android:id="@+id/afl_cotent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.example.library.AutoFlowLayout>
<TextView
android:background="#FFF9F6F6"
android:layout_width="match_parent"
android:layout_height="5dp" />
<TextView
android:text="历史搜索"
android:textSize="17sp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:src="@mipmap/img_empty_medal_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:paddingLeft="8dp"
android:gravity="center"
android:paddingRight="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_attr_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:paddingTop="6dp"
android:paddingLeft="10dp"
android:background="#ff0"
android:paddingRight="10dp"
android:textSize="16sp"
android:textColor="#000"
/>
<!--<TextView-->
<!--android:id="@+id/tv_attr_tag"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->
</LinearLayout>