//流式布局 导入依赖
implementation 'com.github.1002326270xc:LayoutManager-FlowLayout:v1.6'
//整个布局
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/commonBackground"
android:fitsSystemWindows="false"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_35"
android:layout_marginTop="@dimen/dp_52">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_60"
android:background="@drawable/shape_stroke_orange_8"
android:paddingLeft="@dimen/dp_18">
<ImageView
android:id="@+id/iv_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@mipmap/ic_home_search" />
<com.zhenpin.kxx.app.view.ClearTextEditText
android:id="@+id/menu_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dp_8"
android:layout_marginRight="@dimen/dp_8"
android:layout_toRightOf="@id/iv_search"
android:layout_weight="1"
android:background="@null"
android:gravity="center_vertical"
android:hint="请输入搜索商品"
android:singleLine="true"
android:textColor="@color/blank"
android:textColorHint="#999999"
android:textCursorDrawable="@drawable/edittext_shape_two"
android:textSize="@dimen/sp_14" />
</RelativeLayout>
<TextView
android:id="@+id/tv_cantuan"
android:layout_width="@dimen/dp_60"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="取消"
android:textColor="#ff666666"
android:textSize="14sp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/dp_9"
android:background="@drawable/bg_radius"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_search_s"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:visibility="visible"
android:id="@+id/ls_text"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_15"
android:text="历史记录"
android:textColor="#ff000000"
android:textSize="16sp" />
<ImageView
android:id="@+id/delete_ls"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_alignParentRight="true"
android:layout_marginTop="@dimen/dp_16"
android:layout_marginRight="@dimen/dp_20"
android:src="@mipmap/delete" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/histotyRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10" />
<LinearLayout
android:id="@+id/ll_rm_s"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_15"
android:text="热门搜索"
android:textColor="#ff000000"
android:textSize="16sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rm_Recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
activity
//adapter主要设置
FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
histotyRecycler.setLayoutManager(flowLayoutManager);
histotyRecycler.addItemDecoration(new SpaceItemDecoration(dp2px(0)));
adapter = new HistorySearchAdapter(SearchhistoryActivity.this, searchBeans);
histotyRecycler.setAdapter(adapter);
//上边EditText 点击 键盘控制
menuEdit.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
//是否是回车键
if (keyCode == KeyEvent.KEYCODE_ENTER && (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.KEYCODE_SEARCH)) {
//请求一下保存历史记录
if (tags == 1) {
key = menuEdit.getText().toString();
JPushUtils.onEvent(getApplicationContext(), "Search_submit", "点击搜索");
Intent intent = new Intent(SearchhistoryActivity.this, SearchActivity.class);
intent.putExtra("input_title", key);
intent.putExtra("number", number);
intent.putExtra("tag",tags);
intent.putExtra("merchantUuid",merchantUuid);
startActivity(intent);
}else {
key = menuEdit.getText().toString();
mPresenter.getProductCollecList("", "", "", "", key);
}
}
return false;
}
});