|
| 1 | +package com.example.lvruheng.autoflowlayout; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.support.annotation.Nullable; |
| 5 | +import android.support.v7.app.AppCompatActivity; |
| 6 | +import android.view.LayoutInflater; |
| 7 | +import android.view.View; |
| 8 | +import android.widget.Button; |
| 9 | +import android.widget.TextView; |
| 10 | + |
| 11 | +import com.example.library.AutoFlowLayout; |
| 12 | + |
| 13 | +/** |
| 14 | + * Created by lvruheng on 2017/8/4. |
| 15 | + */ |
| 16 | + |
| 17 | +public class NormalFlowActivity extends AppCompatActivity implements View.OnClickListener { |
| 18 | + private AutoFlowLayout mFlowLayout; |
| 19 | + private String[] mData = {"Java","C++","Python","JavaScript","Ruby","Swift","MATLAB","Scratch","Drat","ABAP","COBOL","Fortran","Scala","Lisp", |
| 20 | + "Kotlin","Erlang","Groovy","Scheme","Rust","Logo","Prolog","LabVIEW"}; |
| 21 | + private LayoutInflater mLayoutInflater; |
| 22 | + private Button mSingleButton; |
| 23 | + private Button mMultiLineButton; |
| 24 | + private Button mAddButton; |
| 25 | + private Button mDeleteButton; |
| 26 | + private Button mMultiSelectedButton; |
| 27 | + private Button mCenterButton; |
| 28 | + private int count = 10; |
| 29 | + @Override |
| 30 | + protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 31 | + super.onCreate(savedInstanceState); |
| 32 | + setContentView(R.layout.normal_flow); |
| 33 | + mFlowLayout = (AutoFlowLayout) findViewById(R.id.afl_cotent); |
| 34 | + mLayoutInflater = LayoutInflater.from(this); |
| 35 | + mSingleButton = (Button) findViewById(R.id.bt_single); |
| 36 | + mMultiLineButton = (Button) findViewById(R.id.bt_multi); |
| 37 | + mAddButton = (Button) findViewById(R.id.bt_add); |
| 38 | + mDeleteButton = (Button) findViewById(R.id.bt_delete); |
| 39 | + mMultiSelectedButton = (Button) findViewById(R.id.bt_checked); |
| 40 | + mCenterButton = (Button) findViewById(R.id.bt_center); |
| 41 | + mSingleButton.setOnClickListener(this); |
| 42 | + mMultiLineButton.setOnClickListener(this); |
| 43 | + mAddButton.setOnClickListener(this); |
| 44 | + mDeleteButton.setOnClickListener(this); |
| 45 | + mMultiSelectedButton.setOnClickListener(this); |
| 46 | + mCenterButton.setOnClickListener(this); |
| 47 | + for (int i = 0; i< 10; i ++ ){ |
| 48 | + View item = mLayoutInflater.inflate(R.layout.sub_item, null); |
| 49 | + TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag); |
| 50 | + tvAttrTag.setText(mData[i]); |
| 51 | + mFlowLayout.addView(item); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onClick(View view) { |
| 57 | + switch (view.getId()) { |
| 58 | + case R.id.bt_single:{ |
| 59 | + mFlowLayout.setLineCenter(false); |
| 60 | + mFlowLayout.setSingleLine(true); |
| 61 | + mFlowLayout.setMaxLines(1); |
| 62 | + break; |
| 63 | + } |
| 64 | + case R.id.bt_multi:{ |
| 65 | + mFlowLayout.setLineCenter(false); |
| 66 | + mFlowLayout.setSingleLine(false); |
| 67 | + mFlowLayout.setMaxLines(2); |
| 68 | + break; |
| 69 | + } |
| 70 | + case R.id.bt_add:{ |
| 71 | + mFlowLayout.setLineCenter(false); |
| 72 | + if (count>=mData.length){ |
| 73 | + return; |
| 74 | + } |
| 75 | + View item = mLayoutInflater.inflate(R.layout.sub_item, null); |
| 76 | + TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag); |
| 77 | + tvAttrTag.setText(mData[count]); |
| 78 | + mFlowLayout.setSingleLine(false); |
| 79 | + mFlowLayout.setMaxLines(Integer.MAX_VALUE); |
| 80 | + mFlowLayout.addView(item); |
| 81 | + count++; |
| 82 | + break; |
| 83 | + } |
| 84 | + case R.id.bt_delete:{ |
| 85 | + mFlowLayout.setLineCenter(false); |
| 86 | + mFlowLayout.deleteView(); |
| 87 | + break; |
| 88 | + } |
| 89 | + |
| 90 | + case R.id.bt_checked:{ |
| 91 | + mFlowLayout.setLineCenter(false); |
| 92 | + mFlowLayout.setMultiChecked(true); |
| 93 | + break; |
| 94 | + } |
| 95 | + case R.id.bt_center:{ |
| 96 | + mFlowLayout.setLineCenter(true); |
| 97 | + break; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments