<?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:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.example.cartdamo.MainActivity">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/souzhou"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:hint="搜索你要搜索的手机"
/>
<Button
android:id="@+id/sousuo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="搜索"
android:layout_weight="1"
android:padding="10dp"
/>
</LinearLayout>
<TextView
android:id="@+id/lishi"
android:layout_width="match_parent"
android:layout_height="31dp"
android:text="最近搜索"
android:textStyle="bold" />
<com.fynn.fluidlayout.FluidLayout
android:id="@+id/liu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.fynn.fluidlayout.FluidLayout>
<TextView
android:id="@+id/sousuofaxian"
android:layout_width="match_parent"
android:layout_height="31dp"
android:text="搜索发现"
android:textStyle="bold" />
<com.fynn.fluidlayout.FluidLayout
android:id="@+id/liushi"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.fynn.fluidlayout.FluidLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="购物车"
android:onClick="tiao"
android:textSize="20dp"/>
</LinearLayout>
**********************************************************************
package com.example.cartdamo;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.fynn.fluidlayout.FluidLayout;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private String mNAME[] = {
"考拉三周年人气热销榜",
"电动牙刷",
"尤妮佳",
"豆豆鞋",
"沐浴露",
"日东红茶",
"榴莲",
"电动牙刷",
"雅诗莱黛",
"豆豆鞋"
};
private FluidLayout liu;
private FluidLayout fluidLayout;
private Button button;
private EditText editText;
private List<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
}
private void initView() {
editText = findViewById(R.id.souzhou);
button = findViewById(R.id.sousuo);
fluidLayout = findViewById(R.id.liushi);
liu = findViewById(R.id.liu);
list = new ArrayList<>();
}
private void initData() {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
String liua[] = {s};
for (int i = 0; i < liua.length; i++) {
FluidLayout.LayoutParams params =
new FluidLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(12, 12, 12, 12);
TextView tv = new TextView(MainActivity.this);
tv.setText(liua[i]);
tv.setBackgroundResource(R.drawable.flow_yangshi);
liu.addView(tv, params);
}
}
});
for (int i = 0; i < mNAME.length; i++) {
FluidLayout.LayoutParams params=new FluidLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
params.setMargins(12,12,12,12);
TextView textView= new TextView(this);
textView.setText(mNAME[i]);
textView.setBackgroundResource(R.drawable.flow_yangshi);
textView.setTextColor(Color.BLACK);
fluidLayout.addView(textView,params);
}
}
public void tiao(View view) {
startActivity(new Intent(MainActivity.this,CartActivity.class));
}
}