流式布局

 

 

//布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/auto_tv"
        android:layout_height="35dp"
        android:layout_width="wrap_content"
        android:background="@drawable/a_3"
        android:text="豆豆娃"
        android:textSize="17dp"
        android:gravity="center_horizontal"
        android:layout_marginTop="3dp"
        android:paddingTop="4dp"
        android:layout_marginLeft="8dp"/>
</LinearLayout>

 

搜索的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    >
    <RelativeLayout
        android:layout_width="400dp"
        android:layout_height="35dp"
        android:orientation="horizontal"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        >
        <ImageView
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:src="@drawable/a_4"
            android:layout_marginTop="6dp"
            android:layout_marginLeft="8dp"
            android:id="@+id/search"
            />
        <EditText
            android:layout_width="370dp"
            android:layout_height="30dp"
            android:layout_marginLeft="35dp"
            android:layout_marginTop="3dp"
            android:id="@+id/edit_content"
            android:hint="在万千商品中海选"
            android:background="@null"
            android:textSize="20sp"
            />
    </RelativeLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/diss"
        android:text="取消"
        android:textStyle="bold"
        android:textSize="20sp"
        android:layout_alignParentRight="true"
        android:layout_marginTop="10dp"
        android:layout_marginRight="15dp"
        />
</RelativeLayout>

最近搜索

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="最近搜索"
        android:textSize="20sp"
        android:layout_marginLeft="10dp"
        />
    <ImageView
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:id="@+id/delete"
        android:src="@drawable/rublish"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        />
</RelativeLayout>

主布局加控件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
    >
    <include layout="@layout/sou1"/>
    <include layout="@layout/sou2"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"

        >
        <com.example.library.AutoFlowLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/auto_layout"
            ></com.example.library.AutoFlowLayout>
    </RelativeLayout>
<LinearLayout

    android:layout_marginTop="200dp"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="horizontal"
    >
    <ImageView
        android:id="@+id/One_sao"
        android:layout_width="30dp"


        android:layout_height="30dp"
        android:src="@drawable/sao_kind"
        />
    <EditText
        android:id="@+id/edut_Text"
        android:layout_width="430dp"
        android:layout_height="match_parent"
        android:hint="请输入关键字"

        />

    <ImageView
        android:id="@+id/fang"
        android:layout_width="40dp"
        android:layout_height="30dp"
        android:src="@drawable/a_4"
        />



    <ImageView
        android:id="@+id/di_tu"
        android:layout_width="40dp"
        android:layout_height="30dp"
        android:src="@drawable/ic_location_on_black_24dp"
        />
</LinearLayout>
</LinearLayout>

java代码

       //流式布局

        list = new ArrayList<>();
        search = findViewById(R.id.search);
        edit_content = findViewById(R.id.edit_content);
        diss = findViewById(R.id.diss);
        auto_layout = findViewById(R.id.auto_layout);
        delete = findViewById(R.id.delete);

      //点击事件
        
        search.setOnClickListener(this);
        diss.setOnClickListener(this);
        delete.setOnClickListener(this);

       //流是布局

        @Override
        public void onClick(View v) {
        switch (v.getId()){
            case R.id.search:
                String name = edit_content.getText().toString();

                list.add(name);
                
                auto();

                break;

            case R.id.diss:

                edit_content.getText().clear();

                break;

            case R.id.delete:

                edit_content.getText().clear();
                list.clear();
                auto_layout.removeAllViews();

                break;
        }
    }

       //auto方法
    private void auto() {
        auto_layout.setAdapter(new FlowAdapter(list) {
            @Override
            public View getView(int i) {
                view = View.inflate(MainActivity.this, R.layout.liu_item, null);
                auto_tv = view.findViewById(R.id.auto_tv);
                final String string = list.get(i);
                auto_tv.setText(string);
                list.clear();
                auto_tv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(MainActivity.this, SouActivity.class);
                        intent.putExtra("name",string);
                        startActivity(intent);

                    }
                });
                return view;
            }
        });
    }


  //依赖

implementation 'com.github.LRH1993:AutoFlowLayout:1.0.5'
allprojects {
    repositories {
        google()
        jcenter()
        maven { url  'https://jitpack.io'}
    }
}

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值